2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-08-03 14:12:23 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-08-03 14:12:23 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-08-03 14:12:23 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2016-08-03 14:12:23 +00:00
|
|
|
#include "composite.h"
|
2022-11-05 10:43:41 +00:00
|
|
|
#include "core/outputbackend.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "effectloader.h"
|
|
|
|
#include "effects.h"
|
2023-02-09 13:07:56 +00:00
|
|
|
#include "pointer_input.h"
|
2016-08-03 14:12:23 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
2022-04-22 17:54:31 +00:00
|
|
|
#include "x11window.h"
|
2016-08-03 14:12:23 +00:00
|
|
|
|
|
|
|
#include <KConfigGroup>
|
|
|
|
|
|
|
|
#include <netwm.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_effects_translucency-0");
|
|
|
|
|
|
|
|
class TranslucencyTest : public QObject
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
Q_OBJECT
|
2016-08-03 14:12:23 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testMoveAfterDesktopChange();
|
2016-10-28 12:37:10 +00:00
|
|
|
void testDialogClose();
|
2016-08-03 14:12:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Effect *m_translucencyEffect = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TranslucencyTest::initTestCase()
|
|
|
|
{
|
2018-11-05 13:18:15 +00:00
|
|
|
qputenv("XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8());
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2022-03-23 10:13:38 +00:00
|
|
|
qRegisterMetaType<KWin::Effect *>();
|
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));
|
2022-11-16 21:03:50 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024)));
|
2016-08-03 14:12:23 +00:00
|
|
|
|
|
|
|
// 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"));
|
2021-10-09 15:38:14 +00:00
|
|
|
const auto builtinNames = EffectLoader().listOfKnownEffects();
|
2016-08-03 14:12:23 +00:00
|
|
|
for (QString name : builtinNames) {
|
|
|
|
plugins.writeEntry(name + QStringLiteral("Enabled"), false);
|
|
|
|
}
|
|
|
|
config->group("Outline").writeEntry(QStringLiteral("QmlPath"), QString("/does/not/exist.qml"));
|
2016-11-16 12:42:45 +00:00
|
|
|
config->group("Effect-kwin4_effect_translucency").writeEntry(QStringLiteral("Dialogs"), 90);
|
2016-08-03 14:12:23 +00:00
|
|
|
|
|
|
|
config->sync();
|
|
|
|
kwinApp()->setConfig(config);
|
|
|
|
|
2016-08-10 07:24:53 +00:00
|
|
|
qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", "1");
|
2016-08-03 14:12:23 +00:00
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2016-08-03 14:12:23 +00:00
|
|
|
QVERIFY(Compositor::self());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TranslucencyTest::init()
|
|
|
|
{
|
|
|
|
// load the translucency effect
|
2022-03-23 10:13:38 +00:00
|
|
|
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl *>(effects);
|
2016-08-03 14:12:23 +00:00
|
|
|
// find the effectsloader
|
2022-03-23 10:13:38 +00:00
|
|
|
auto effectloader = e->findChild<AbstractEffectLoader *>();
|
2016-08-03 14:12:23 +00:00
|
|
|
QVERIFY(effectloader);
|
|
|
|
QSignalSpy effectLoadedSpy(effectloader, &AbstractEffectLoader::effectLoaded);
|
|
|
|
|
|
|
|
QVERIFY(!e->isEffectLoaded(QStringLiteral("kwin4_effect_translucency")));
|
|
|
|
QVERIFY(e->loadEffect(QStringLiteral("kwin4_effect_translucency")));
|
|
|
|
QVERIFY(e->isEffectLoaded(QStringLiteral("kwin4_effect_translucency")));
|
|
|
|
|
|
|
|
QCOMPARE(effectLoadedSpy.count(), 1);
|
2022-03-23 10:13:38 +00:00
|
|
|
m_translucencyEffect = effectLoadedSpy.first().first().value<Effect *>();
|
2016-08-03 14:12:23 +00:00
|
|
|
QVERIFY(m_translucencyEffect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TranslucencyTest::cleanup()
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl *>(effects);
|
2016-08-03 14:12:23 +00:00
|
|
|
if (e->isEffectLoaded(QStringLiteral("kwin4_effect_translucency"))) {
|
|
|
|
e->unloadEffect(QStringLiteral("kwin4_effect_translucency"));
|
|
|
|
}
|
|
|
|
QVERIFY(!e->isEffectLoaded(QStringLiteral("kwin4_effect_translucency")));
|
|
|
|
m_translucencyEffect = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TranslucencyTest::testMoveAfterDesktopChange()
|
|
|
|
{
|
|
|
|
// test tries to simulate the condition of bug 366081
|
|
|
|
QVERIFY(!m_translucencyEffect->isActive());
|
|
|
|
|
|
|
|
QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded);
|
|
|
|
|
|
|
|
// create an xcb window
|
2023-02-03 13:29:21 +00:00
|
|
|
Test::XcbConnectionPtr c = Test::createX11Connection();
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2016-08-03 14:12:23 +00:00
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2016-08-03 14:12:23 +00:00
|
|
|
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());
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
xcb_flush(c.get());
|
2016-08-03 14:12:23 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// we should get a window for it
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2016-08-03 14:12:23 +00:00
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
QVERIFY(window);
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
QVERIFY(window->isDecorated());
|
2016-08-03 14:12:23 +00:00
|
|
|
|
|
|
|
QVERIFY(windowAddedSpy.wait());
|
|
|
|
QVERIFY(!m_translucencyEffect->isActive());
|
|
|
|
// let's send the window to desktop 2
|
|
|
|
effects->setNumberOfDesktops(2);
|
|
|
|
QCOMPARE(effects->numberOfDesktops(), 2);
|
2022-04-23 19:51:16 +00:00
|
|
|
workspace()->sendWindowToDesktop(window, 2, false);
|
2016-08-03 14:12:23 +00:00
|
|
|
effects->setCurrentDesktop(2);
|
|
|
|
QVERIFY(!m_translucencyEffect->isActive());
|
2023-02-09 13:07:56 +00:00
|
|
|
KWin::input()->pointer()->warp(window->frameGeometry().center());
|
2022-04-23 19:51:16 +00:00
|
|
|
workspace()->performWindowOperation(window, Options::MoveOp);
|
2016-08-03 14:12:23 +00:00
|
|
|
QVERIFY(m_translucencyEffect->isActive());
|
|
|
|
QTest::qWait(200);
|
|
|
|
QVERIFY(m_translucencyEffect->isActive());
|
|
|
|
// now end move resize
|
2022-04-23 19:51:16 +00:00
|
|
|
window->endInteractiveMoveResize();
|
2016-08-03 14:12:23 +00:00
|
|
|
QVERIFY(m_translucencyEffect->isActive());
|
|
|
|
QTest::qWait(500);
|
2017-08-08 18:48:40 +00:00
|
|
|
QTRY_VERIFY(!m_translucencyEffect->isActive());
|
2016-08-03 14:12:23 +00:00
|
|
|
|
|
|
|
// and destroy the window again
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
xcb_flush(c.get());
|
2016-08-03 14:12:23 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2016-08-03 14:12:23 +00:00
|
|
|
QVERIFY(windowClosedSpy.wait());
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_destroy_window(c.get(), windowId);
|
2016-08-03 14:12:23 +00:00
|
|
|
c.reset();
|
|
|
|
}
|
|
|
|
|
2016-10-28 12:37:10 +00:00
|
|
|
void TranslucencyTest::testDialogClose()
|
|
|
|
{
|
|
|
|
// this test simulates the condition of BUG 342716
|
|
|
|
// with translucency settings for window type dialog the effect never ends when the window gets destroyed
|
|
|
|
QVERIFY(!m_translucencyEffect->isActive());
|
|
|
|
QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded);
|
|
|
|
|
|
|
|
// create an xcb window
|
2023-02-03 13:29:21 +00:00
|
|
|
Test::XcbConnectionPtr c = Test::createX11Connection();
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2016-10-28 12:37:10 +00:00
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2016-10-28 12:37:10 +00:00
|
|
|
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());
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
NETWinInfo winInfo(c.get(), windowId, rootWindow(), NET::Properties(), NET::Properties2());
|
2016-10-28 12:37:10 +00:00
|
|
|
winInfo.setWindowType(NET::Dialog);
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
xcb_flush(c.get());
|
2016-10-28 12:37:10 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// we should get a window for it
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2016-10-28 12:37:10 +00:00
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
QVERIFY(window);
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
QVERIFY(window->isDecorated());
|
|
|
|
QVERIFY(window->isDialog());
|
2016-10-28 12:37:10 +00:00
|
|
|
|
|
|
|
QVERIFY(windowAddedSpy.wait());
|
|
|
|
QTRY_VERIFY(m_translucencyEffect->isActive());
|
|
|
|
// and destroy the window again
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
xcb_flush(c.get());
|
2016-10-28 12:37:10 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2016-10-28 12:37:10 +00:00
|
|
|
|
|
|
|
QSignalSpy windowDeletedSpy(effects, &EffectsHandler::windowDeleted);
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
if (windowDeletedSpy.isEmpty()) {
|
|
|
|
QVERIFY(windowDeletedSpy.wait());
|
|
|
|
}
|
|
|
|
QCOMPARE(windowDeletedSpy.count(), 1);
|
|
|
|
QTRY_VERIFY(!m_translucencyEffect->isActive());
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_destroy_window(c.get(), windowId);
|
2016-10-28 12:37:10 +00:00
|
|
|
c.reset();
|
|
|
|
}
|
|
|
|
|
2016-08-03 14:12:23 +00:00
|
|
|
WAYLANDTEST_MAIN(TranslucencyTest)
|
|
|
|
#include "translucency_test.moc"
|