2016-10-30 10:27:38 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
#include "composite.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "effectloader.h"
|
|
|
|
#include "cursor.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "shell_client.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "effect_builtins.h"
|
|
|
|
|
|
|
|
#include <KConfigGroup>
|
|
|
|
|
2016-10-31 07:43:35 +00:00
|
|
|
#include <KWayland/Client/connection_thread.h>
|
|
|
|
#include <KWayland/Client/registry.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
#include <KWayland/Client/shell.h>
|
|
|
|
#include <KWayland/Client/slide.h>
|
|
|
|
|
2016-10-30 10:27:38 +00:00
|
|
|
#include <netwm.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_effects_slidingpopups-0");
|
|
|
|
|
|
|
|
class SlidingPopupsTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testWithOtherEffect_data();
|
|
|
|
void testWithOtherEffect();
|
2016-10-31 07:43:35 +00:00
|
|
|
void testWithOtherEffectWayland_data();
|
|
|
|
void testWithOtherEffectWayland();
|
2016-10-30 10:27:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void SlidingPopupsTest::initTestCase()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<KWin::ShellClient*>();
|
|
|
|
qRegisterMetaType<KWin::AbstractClient*>();
|
|
|
|
qRegisterMetaType<KWin::Effect*>();
|
|
|
|
QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
|
|
|
|
QVERIFY(workspaceCreatedSpy.isValid());
|
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
|
|
|
QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit()));
|
|
|
|
|
|
|
|
// disable all effects - we don't want to have it interact with the rendering
|
|
|
|
auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
|
|
KConfigGroup plugins(config, QStringLiteral("Plugins"));
|
|
|
|
ScriptedEffectLoader loader;
|
|
|
|
const auto builtinNames = BuiltInEffects::availableEffectNames() << loader.listOfKnownEffects();
|
|
|
|
for (QString name : builtinNames) {
|
|
|
|
plugins.writeEntry(name + QStringLiteral("Enabled"), false);
|
|
|
|
}
|
2016-12-02 19:27:43 +00:00
|
|
|
KConfigGroup wobblyGroup = config->group("Effect-Wobbly");
|
|
|
|
wobblyGroup.writeEntry(QStringLiteral("Settings"), QStringLiteral("Custom"));
|
|
|
|
wobblyGroup.writeEntry(QStringLiteral("OpenEffect"), true);
|
|
|
|
wobblyGroup.writeEntry(QStringLiteral("CloseEffect"), true);
|
2016-10-30 10:27:38 +00:00
|
|
|
|
|
|
|
config->sync();
|
|
|
|
kwinApp()->setConfig(config);
|
|
|
|
|
2016-10-31 06:47:26 +00:00
|
|
|
if (QFile::exists(QStringLiteral("/dev/dri/card0"))) {
|
|
|
|
qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2"));
|
|
|
|
}
|
2016-10-30 10:27:38 +00:00
|
|
|
qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", "1");
|
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(workspaceCreatedSpy.wait());
|
|
|
|
QVERIFY(Compositor::self());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlidingPopupsTest::init()
|
|
|
|
{
|
2016-12-03 13:31:14 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
|
2016-10-30 10:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SlidingPopupsTest::cleanup()
|
|
|
|
{
|
2016-10-31 07:43:35 +00:00
|
|
|
Test::destroyWaylandConnection();
|
2016-10-30 10:27:38 +00:00
|
|
|
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects);
|
|
|
|
while (!e->loadedEffects().isEmpty()) {
|
|
|
|
const QString effect = e->loadedEffects().first();
|
|
|
|
e->unloadEffect(effect);
|
|
|
|
QVERIFY(!e->isEffectLoaded(effect));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct XcbConnectionDeleter
|
|
|
|
{
|
|
|
|
static inline void cleanup(xcb_connection_t *pointer)
|
|
|
|
{
|
|
|
|
xcb_disconnect(pointer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void SlidingPopupsTest::testWithOtherEffect_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QStringList>("effectsToLoad");
|
|
|
|
|
|
|
|
QTest::newRow("scale, slide") << QStringList{QStringLiteral("kwin4_effect_scalein"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, scale") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("kwin4_effect_scalein")};
|
2016-10-31 06:47:26 +00:00
|
|
|
QTest::newRow("fade, slide") << QStringList{QStringLiteral("kwin4_effect_fade"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, fade") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("kwin4_effect_fade")};
|
|
|
|
|
|
|
|
if (effects->compositingType() & KWin::OpenGLCompositing) {
|
|
|
|
QTest::newRow("glide, slide") << QStringList{QStringLiteral("glide"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, glide") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("glide")};
|
|
|
|
QTest::newRow("wobblywindows, slide") << QStringList{QStringLiteral("wobblywindows"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, wobblywindows") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("wobblywindows")};
|
|
|
|
QTest::newRow("fallapart, slide") << QStringList{QStringLiteral("fallapart"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, fallapart") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("fallapart")};
|
|
|
|
}
|
2016-10-30 10:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SlidingPopupsTest::testWithOtherEffect()
|
|
|
|
{
|
|
|
|
// this test verifies that slidingpopups effect grabs the window added role
|
|
|
|
// independently of the sequence how the effects are loaded.
|
|
|
|
// see BUG 336866
|
|
|
|
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects);
|
|
|
|
// find the effectsloader
|
|
|
|
auto effectloader = e->findChild<AbstractEffectLoader*>();
|
|
|
|
QVERIFY(effectloader);
|
|
|
|
QSignalSpy effectLoadedSpy(effectloader, &AbstractEffectLoader::effectLoaded);
|
|
|
|
QVERIFY(effectLoadedSpy.isValid());
|
|
|
|
|
|
|
|
Effect *slidingPoupus = nullptr;
|
|
|
|
Effect *otherEffect = nullptr;
|
|
|
|
QFETCH(QStringList, effectsToLoad);
|
|
|
|
for (const QString &effectName : effectsToLoad) {
|
|
|
|
QVERIFY(!e->isEffectLoaded(effectName));
|
|
|
|
QVERIFY(e->loadEffect(effectName));
|
|
|
|
QVERIFY(e->isEffectLoaded(effectName));
|
|
|
|
|
|
|
|
QCOMPARE(effectLoadedSpy.count(), 1);
|
|
|
|
Effect *effect = effectLoadedSpy.first().first().value<Effect*>();
|
|
|
|
if (effectName == QStringLiteral("slidingpopups")) {
|
|
|
|
slidingPoupus = effect;
|
|
|
|
} else {
|
|
|
|
otherEffect = effect;
|
|
|
|
}
|
|
|
|
effectLoadedSpy.clear();
|
|
|
|
}
|
|
|
|
QVERIFY(slidingPoupus);
|
|
|
|
QVERIFY(otherEffect);
|
|
|
|
|
|
|
|
QVERIFY(!slidingPoupus->isActive());
|
|
|
|
QVERIFY(!otherEffect->isActive());
|
2016-10-31 07:55:54 +00:00
|
|
|
|
|
|
|
// give the compositor some time to render
|
|
|
|
QTest::qWait(50);
|
|
|
|
|
2016-10-30 10:27:38 +00:00
|
|
|
QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded);
|
|
|
|
QVERIFY(windowAddedSpy.isValid());
|
|
|
|
|
|
|
|
// create an xcb window
|
|
|
|
QScopedPointer<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.data()));
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
|
|
|
xcb_window_t w = xcb_generate_id(c.data());
|
|
|
|
xcb_create_window(c.data(), XCB_COPY_FROM_PARENT, w, rootWindow(),
|
|
|
|
windowGeometry.x(),
|
|
|
|
windowGeometry.y(),
|
|
|
|
windowGeometry.width(),
|
|
|
|
windowGeometry.height(),
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.data(), w, &hints);
|
2016-10-31 06:47:26 +00:00
|
|
|
NETWinInfo winInfo(c.data(), w, rootWindow(), NET::Properties(), NET::Properties2());
|
|
|
|
winInfo.setWindowType(NET::Normal);
|
2016-10-30 10:27:38 +00:00
|
|
|
|
|
|
|
// and get the slide atom
|
|
|
|
const QByteArray effectAtomName = QByteArrayLiteral("_KDE_SLIDE");
|
|
|
|
xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c.data(), false, effectAtomName.length(), effectAtomName.constData());
|
|
|
|
const int size = 2;
|
|
|
|
int32_t data[size];
|
|
|
|
data[0] = 0;
|
|
|
|
data[1] = 0;
|
|
|
|
QScopedPointer<xcb_intern_atom_reply_t, QScopedPointerPodDeleter> atom(xcb_intern_atom_reply(c.data(), atomCookie, nullptr));
|
|
|
|
QVERIFY(!atom.isNull());
|
|
|
|
xcb_change_property(c.data(), XCB_PROP_MODE_REPLACE, w, atom->atom, atom->atom, 32, size, data);
|
|
|
|
|
|
|
|
xcb_map_window(c.data(), w);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
|
|
|
|
// we should get a client for it
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::clientAdded);
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
|
|
|
Client *client = windowCreatedSpy.first().first().value<Client*>();
|
|
|
|
QVERIFY(client);
|
|
|
|
QCOMPARE(client->window(), w);
|
2016-10-31 06:47:26 +00:00
|
|
|
QVERIFY(client->isNormalWindow());
|
2016-10-30 10:27:38 +00:00
|
|
|
|
|
|
|
// sliding popups should be active
|
|
|
|
QVERIFY(windowAddedSpy.wait());
|
|
|
|
QTRY_VERIFY(slidingPoupus->isActive());
|
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
|
|
|
|
// wait till effect ends
|
|
|
|
QTRY_VERIFY(!slidingPoupus->isActive());
|
2016-10-31 06:47:26 +00:00
|
|
|
QTest::qWait(300);
|
2016-10-30 10:27:38 +00:00
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
|
|
|
|
// and destroy the window again
|
|
|
|
xcb_unmap_window(c.data(), w);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
|
|
|
|
QSignalSpy windowClosedSpy(client, &Client::windowClosed);
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
|
|
|
|
|
|
|
QSignalSpy windowDeletedSpy(effects, &EffectsHandler::windowDeleted);
|
|
|
|
QVERIFY(windowDeletedSpy.isValid());
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
|
|
|
|
// again we should have the sliding popups active
|
|
|
|
QVERIFY(slidingPoupus->isActive());
|
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
|
|
|
|
QVERIFY(windowDeletedSpy.wait());
|
|
|
|
|
|
|
|
QCOMPARE(windowDeletedSpy.count(), 1);
|
|
|
|
QTRY_VERIFY(!slidingPoupus->isActive());
|
2016-10-31 06:47:26 +00:00
|
|
|
QTest::qWait(300);
|
2016-10-30 10:27:38 +00:00
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
xcb_destroy_window(c.data(), w);
|
|
|
|
c.reset();
|
|
|
|
}
|
|
|
|
|
2016-10-31 07:43:35 +00:00
|
|
|
void SlidingPopupsTest::testWithOtherEffectWayland_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QStringList>("effectsToLoad");
|
|
|
|
|
|
|
|
QTest::newRow("scale, slide") << QStringList{QStringLiteral("kwin4_effect_scalein"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, scale") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("kwin4_effect_scalein")};
|
|
|
|
QTest::newRow("fade, slide") << QStringList{QStringLiteral("kwin4_effect_fade"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, fade") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("kwin4_effect_fade")};
|
|
|
|
|
|
|
|
if (effects->compositingType() & KWin::OpenGLCompositing) {
|
|
|
|
QTest::newRow("glide, slide") << QStringList{QStringLiteral("glide"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, glide") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("glide")};
|
|
|
|
QTest::newRow("wobblywindows, slide") << QStringList{QStringLiteral("wobblywindows"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, wobblywindows") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("wobblywindows")};
|
|
|
|
QTest::newRow("fallapart, slide") << QStringList{QStringLiteral("fallapart"), QStringLiteral("slidingpopups")};
|
|
|
|
QTest::newRow("slide, fallapart") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("fallapart")};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlidingPopupsTest::testWithOtherEffectWayland()
|
|
|
|
{
|
|
|
|
// this test verifies that slidingpopups effect grabs the window added role
|
|
|
|
// independently of the sequence how the effects are loaded.
|
|
|
|
// see BUG 336866
|
|
|
|
// the test is like testWithOtherEffect, but simulates using a Wayland window
|
|
|
|
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects);
|
|
|
|
// find the effectsloader
|
|
|
|
auto effectloader = e->findChild<AbstractEffectLoader*>();
|
|
|
|
QVERIFY(effectloader);
|
|
|
|
QSignalSpy effectLoadedSpy(effectloader, &AbstractEffectLoader::effectLoaded);
|
|
|
|
QVERIFY(effectLoadedSpy.isValid());
|
|
|
|
|
|
|
|
Effect *slidingPoupus = nullptr;
|
|
|
|
Effect *otherEffect = nullptr;
|
|
|
|
QFETCH(QStringList, effectsToLoad);
|
|
|
|
for (const QString &effectName : effectsToLoad) {
|
|
|
|
QVERIFY(!e->isEffectLoaded(effectName));
|
|
|
|
QVERIFY(e->loadEffect(effectName));
|
|
|
|
QVERIFY(e->isEffectLoaded(effectName));
|
|
|
|
|
|
|
|
QCOMPARE(effectLoadedSpy.count(), 1);
|
|
|
|
Effect *effect = effectLoadedSpy.first().first().value<Effect*>();
|
|
|
|
if (effectName == QStringLiteral("slidingpopups")) {
|
|
|
|
slidingPoupus = effect;
|
|
|
|
} else {
|
|
|
|
otherEffect = effect;
|
|
|
|
}
|
|
|
|
effectLoadedSpy.clear();
|
|
|
|
}
|
|
|
|
QVERIFY(slidingPoupus);
|
|
|
|
QVERIFY(otherEffect);
|
|
|
|
|
|
|
|
QVERIFY(!slidingPoupus->isActive());
|
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded);
|
|
|
|
QVERIFY(windowAddedSpy.isValid());
|
|
|
|
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
// the test created the slide protocol, let's create a Registry and listen for it
|
|
|
|
QScopedPointer<Registry> registry(new Registry);
|
|
|
|
registry->create(Test::waylandConnection());
|
|
|
|
|
|
|
|
QSignalSpy interfacesAnnouncedSpy(registry.data(), &Registry::interfacesAnnounced);
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.isValid());
|
|
|
|
registry->setup();
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.wait());
|
|
|
|
auto slideInterface = registry->interface(Registry::Interface::Slide);
|
|
|
|
QVERIFY(slideInterface.name != 0);
|
|
|
|
QScopedPointer<SlideManager> slideManager(registry->createSlideManager(slideInterface.name, slideInterface.version));
|
|
|
|
QVERIFY(slideManager);
|
|
|
|
|
|
|
|
// create Wayland window
|
|
|
|
QScopedPointer<Surface> surface(Test::createSurface());
|
|
|
|
QVERIFY(surface);
|
|
|
|
QScopedPointer<Slide> slide(slideManager->createSlide(surface.data()));
|
|
|
|
slide->setLocation(Slide::Location::Left);
|
|
|
|
slide->commit();
|
|
|
|
QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data()));
|
|
|
|
QVERIFY(shellSurface);
|
|
|
|
QCOMPARE(windowAddedSpy.count(), 0);
|
|
|
|
auto client = Test::renderAndWaitForShown(surface.data(), QSize(10, 20), Qt::blue);
|
|
|
|
QVERIFY(client);
|
|
|
|
QVERIFY(client->isNormalWindow());
|
|
|
|
|
|
|
|
// sliding popups should be active
|
|
|
|
QCOMPARE(windowAddedSpy.count(), 1);
|
|
|
|
QTRY_VERIFY(slidingPoupus->isActive());
|
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
|
|
|
|
// wait till effect ends
|
|
|
|
QTRY_VERIFY(!slidingPoupus->isActive());
|
|
|
|
QTest::qWait(300);
|
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
|
|
|
|
// and destroy the window again
|
|
|
|
shellSurface.reset();
|
|
|
|
surface.reset();
|
|
|
|
|
|
|
|
QSignalSpy windowClosedSpy(client, &Client::windowClosed);
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
|
|
|
|
|
|
|
QSignalSpy windowDeletedSpy(effects, &EffectsHandler::windowDeleted);
|
|
|
|
QVERIFY(windowDeletedSpy.isValid());
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
|
|
|
|
// again we should have the sliding popups active
|
|
|
|
QVERIFY(slidingPoupus->isActive());
|
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
|
|
|
|
QVERIFY(windowDeletedSpy.wait());
|
|
|
|
|
|
|
|
QCOMPARE(windowDeletedSpy.count(), 1);
|
|
|
|
QTRY_VERIFY(!slidingPoupus->isActive());
|
|
|
|
QTest::qWait(300);
|
|
|
|
QVERIFY(!otherEffect->isActive());
|
|
|
|
}
|
|
|
|
|
2016-10-30 10:27:38 +00:00
|
|
|
WAYLANDTEST_MAIN(SlidingPopupsTest)
|
|
|
|
#include "slidingpopups_test.moc"
|