2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2016-03-09 15:17:01 +00:00
|
|
|
// Qt
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2016-03-09 15:17:01 +00:00
|
|
|
// KWayland
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/compositor.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/plasmashell.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/connection_thread.h"
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/event_queue.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/plasmashell.h"
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/surface.h"
|
2016-03-09 15:17:01 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-03-09 15:17:01 +00:00
|
|
|
|
|
|
|
class TestPlasmaShell : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testRole_data();
|
|
|
|
void testRole();
|
2016-06-10 14:44:29 +00:00
|
|
|
void testPosition();
|
2016-06-13 09:32:05 +00:00
|
|
|
void testSkipTaskbar();
|
2018-05-22 12:11:22 +00:00
|
|
|
void testSkipSwitcher();
|
2016-06-13 12:01:49 +00:00
|
|
|
void testPanelBehavior_data();
|
|
|
|
void testPanelBehavior();
|
2016-10-10 14:42:05 +00:00
|
|
|
void testAutoHidePanel();
|
2016-10-12 12:40:25 +00:00
|
|
|
void testPanelTakesFocus();
|
2016-05-19 13:17:07 +00:00
|
|
|
void testDisconnect();
|
2016-06-17 13:32:31 +00:00
|
|
|
void testWhileDestroying();
|
2016-03-09 15:17:01 +00:00
|
|
|
|
|
|
|
private:
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display = nullptr;
|
2016-03-09 15:17:01 +00:00
|
|
|
CompositorInterface *m_compositorInterface = nullptr;
|
|
|
|
PlasmaShellInterface *m_plasmaShellInterface = nullptr;
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection = nullptr;
|
|
|
|
KWayland::Client::Compositor *m_compositor = nullptr;
|
|
|
|
KWayland::Client::EventQueue *m_queue = nullptr;
|
2016-03-09 15:17:01 +00:00
|
|
|
QThread *m_thread = nullptr;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry *m_registry = nullptr;
|
|
|
|
KWayland::Client::PlasmaShell *m_plasmaShell = nullptr;
|
2016-03-09 15:17:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-wayland-plasma-shell-0");
|
|
|
|
|
|
|
|
void TestPlasmaShell::init()
|
|
|
|
{
|
|
|
|
delete m_display;
|
2023-09-13 17:59:29 +00:00
|
|
|
m_display = new KWin::Display(this);
|
2020-10-19 15:52:56 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
2016-03-09 15:17:01 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
2016-03-09 15:17:01 +00:00
|
|
|
m_display->createShm();
|
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_plasmaShellInterface = new PlasmaShellInterface(m_display, m_display);
|
2016-03-09 15:17:01 +00:00
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2016-03-09 15:17:01 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
2016-03-09 15:17:01 +00:00
|
|
|
QVERIFY(!m_queue->isValid());
|
|
|
|
m_queue->setup(m_connection);
|
|
|
|
QVERIFY(m_queue->isValid());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_registry = new KWayland::Client::Registry();
|
|
|
|
QSignalSpy interfacesAnnouncedSpy(m_registry, &KWayland::Client::Registry::interfaceAnnounced);
|
2016-03-09 15:17:01 +00:00
|
|
|
|
|
|
|
QVERIFY(!m_registry->eventQueue());
|
|
|
|
m_registry->setEventQueue(m_queue);
|
|
|
|
QCOMPARE(m_registry->eventQueue(), m_queue);
|
|
|
|
m_registry->create(m_connection);
|
|
|
|
QVERIFY(m_registry->isValid());
|
|
|
|
m_registry->setup();
|
|
|
|
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.wait());
|
2022-04-19 10:14:26 +00:00
|
|
|
#define CREATE(variable, factory, iface) \
|
|
|
|
variable = \
|
2022-11-08 21:15:17 +00:00
|
|
|
m_registry->create##factory(m_registry->interface(KWayland::Client::Registry::Interface::iface).name, m_registry->interface(KWayland::Client::Registry::Interface::iface).version, this); \
|
2016-03-09 15:17:01 +00:00
|
|
|
QVERIFY(variable);
|
|
|
|
|
|
|
|
CREATE(m_compositor, Compositor, Compositor)
|
|
|
|
CREATE(m_plasmaShell, PlasmaShell, PlasmaShell)
|
|
|
|
|
|
|
|
#undef CREATE
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPlasmaShell::cleanup()
|
|
|
|
{
|
2022-04-19 10:14:26 +00:00
|
|
|
#define DELETE(name) \
|
|
|
|
if (name) { \
|
|
|
|
delete name; \
|
|
|
|
name = nullptr; \
|
2016-03-09 15:17:01 +00:00
|
|
|
}
|
|
|
|
DELETE(m_plasmaShell)
|
|
|
|
DELETE(m_compositor)
|
|
|
|
DELETE(m_queue)
|
|
|
|
DELETE(m_registry)
|
|
|
|
#undef DELETE
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
delete m_connection;
|
|
|
|
m_connection = nullptr;
|
|
|
|
|
|
|
|
delete m_display;
|
|
|
|
m_display = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPlasmaShell::testRole_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWayland::Client::PlasmaShellSurface::Role>("clientRole");
|
2023-09-13 17:59:29 +00:00
|
|
|
QTest::addColumn<KWin::PlasmaShellSurfaceInterface::Role>("serverRole");
|
2016-03-09 15:17:01 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("desktop") << KWayland::Client::PlasmaShellSurface::Role::Desktop << PlasmaShellSurfaceInterface::Role::Desktop;
|
|
|
|
QTest::newRow("osd") << KWayland::Client::PlasmaShellSurface::Role::OnScreenDisplay << PlasmaShellSurfaceInterface::Role::OnScreenDisplay;
|
|
|
|
QTest::newRow("panel") << KWayland::Client::PlasmaShellSurface::Role::Panel << PlasmaShellSurfaceInterface::Role::Panel;
|
|
|
|
QTest::newRow("notification") << KWayland::Client::PlasmaShellSurface::Role::Notification << PlasmaShellSurfaceInterface::Role::Notification;
|
|
|
|
QTest::newRow("tooltip") << KWayland::Client::PlasmaShellSurface::Role::ToolTip << PlasmaShellSurfaceInterface::Role::ToolTip;
|
|
|
|
QTest::newRow("criticalnotification") << KWayland::Client::PlasmaShellSurface::Role::CriticalNotification << PlasmaShellSurfaceInterface::Role::CriticalNotification;
|
|
|
|
QTest::newRow("appletPopup") << KWayland::Client::PlasmaShellSurface::Role::AppletPopup << PlasmaShellSurfaceInterface::Role::AppletPopup;
|
2016-03-09 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPlasmaShell::testRole()
|
|
|
|
{
|
|
|
|
// this test verifies that setting the role on a plasma shell surface works
|
|
|
|
|
|
|
|
// first create signal spies
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
|
|
|
|
|
|
|
// create the surface
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2016-06-10 13:46:40 +00:00
|
|
|
// no PlasmaShellSurface for the Surface yet yet
|
2022-11-08 21:15:17 +00:00
|
|
|
QVERIFY(!KWayland::Client::PlasmaShellSurface::get(s.get()));
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
|
|
|
QCOMPARE(ps->role(), KWayland::Client::PlasmaShellSurface::Role::Normal);
|
2016-06-10 13:46:40 +00:00
|
|
|
// now we should have a PlasmaShellSurface for
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(KWayland::Client::PlasmaShellSurface::get(s.get()), ps.get());
|
2016-03-09 15:17:01 +00:00
|
|
|
|
2016-06-10 13:38:05 +00:00
|
|
|
// try to create another PlasmaShellSurface for the same Surface, should return from cache
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(m_plasmaShell->createSurface(s.get()), ps.get());
|
2016-06-10 13:38:05 +00:00
|
|
|
|
2016-03-09 15:17:01 +00:00
|
|
|
// and get them on the server
|
|
|
|
QVERIFY(plasmaSurfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
|
|
|
|
QCOMPARE(surfaceCreatedSpy.count(), 1);
|
|
|
|
|
|
|
|
// verify that we got a plasma shell surface
|
2021-08-29 05:11:06 +00:00
|
|
|
auto sps = plasmaSurfaceCreatedSpy.first().first().value<PlasmaShellSurfaceInterface *>();
|
2016-03-09 15:17:01 +00:00
|
|
|
QVERIFY(sps);
|
|
|
|
QVERIFY(sps->surface());
|
2021-08-29 05:11:06 +00:00
|
|
|
QCOMPARE(sps->surface(), surfaceCreatedSpy.first().first().value<SurfaceInterface *>());
|
2016-03-09 15:17:01 +00:00
|
|
|
|
|
|
|
// default role should be normal
|
|
|
|
QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Normal);
|
|
|
|
|
|
|
|
// now change it
|
|
|
|
QSignalSpy roleChangedSpy(sps, &PlasmaShellSurfaceInterface::roleChanged);
|
2022-11-08 21:15:17 +00:00
|
|
|
QFETCH(KWayland::Client::PlasmaShellSurface::Role, clientRole);
|
2016-03-09 15:17:01 +00:00
|
|
|
ps->setRole(clientRole);
|
2016-06-10 13:50:20 +00:00
|
|
|
QCOMPARE(ps->role(), clientRole);
|
2016-03-09 15:17:01 +00:00
|
|
|
QVERIFY(roleChangedSpy.wait());
|
|
|
|
QCOMPARE(roleChangedSpy.count(), 1);
|
|
|
|
QTEST(sps->role(), "serverRole");
|
2016-06-10 13:50:20 +00:00
|
|
|
|
2016-06-13 14:01:54 +00:00
|
|
|
// try changing again should not emit the signal
|
|
|
|
ps->setRole(clientRole);
|
|
|
|
QVERIFY(!roleChangedSpy.wait(100));
|
|
|
|
|
2016-06-10 13:50:20 +00:00
|
|
|
// set role back to normal
|
2022-11-08 21:15:17 +00:00
|
|
|
ps->setRole(KWayland::Client::PlasmaShellSurface::Role::Normal);
|
|
|
|
QCOMPARE(ps->role(), KWayland::Client::PlasmaShellSurface::Role::Normal);
|
2016-06-10 13:50:20 +00:00
|
|
|
QVERIFY(roleChangedSpy.wait());
|
|
|
|
QCOMPARE(roleChangedSpy.count(), 2);
|
|
|
|
QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Normal);
|
2016-03-09 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 14:44:29 +00:00
|
|
|
void TestPlasmaShell::testPosition()
|
|
|
|
{
|
|
|
|
// this test verifies that updating the position of a PlasmaShellSurface is properly passed to the server
|
|
|
|
QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
2016-06-10 14:44:29 +00:00
|
|
|
QVERIFY(plasmaSurfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
|
|
|
|
|
|
|
|
// verify that we got a plasma shell surface
|
2021-08-29 05:11:06 +00:00
|
|
|
auto sps = plasmaSurfaceCreatedSpy.first().first().value<PlasmaShellSurfaceInterface *>();
|
2016-06-10 14:44:29 +00:00
|
|
|
QVERIFY(sps);
|
|
|
|
QVERIFY(sps->surface());
|
|
|
|
|
|
|
|
// default position should not be set
|
|
|
|
QVERIFY(!sps->isPositionSet());
|
|
|
|
QCOMPARE(sps->position(), QPoint());
|
|
|
|
|
|
|
|
// now let's try to change the position
|
|
|
|
QSignalSpy positionChangedSpy(sps, &PlasmaShellSurfaceInterface::positionChanged);
|
|
|
|
ps->setPosition(QPoint(1, 2));
|
|
|
|
QVERIFY(positionChangedSpy.wait());
|
|
|
|
QCOMPARE(positionChangedSpy.count(), 1);
|
|
|
|
QVERIFY(sps->isPositionSet());
|
|
|
|
QCOMPARE(sps->position(), QPoint(1, 2));
|
|
|
|
|
|
|
|
// let's try to set same position, should not trigger an update
|
|
|
|
ps->setPosition(QPoint(1, 2));
|
|
|
|
QVERIFY(!positionChangedSpy.wait(100));
|
|
|
|
// different point should work, though
|
|
|
|
ps->setPosition(QPoint(3, 4));
|
|
|
|
QVERIFY(positionChangedSpy.wait());
|
|
|
|
QCOMPARE(positionChangedSpy.count(), 2);
|
|
|
|
QCOMPARE(sps->position(), QPoint(3, 4));
|
|
|
|
}
|
|
|
|
|
2016-06-13 09:32:05 +00:00
|
|
|
void TestPlasmaShell::testSkipTaskbar()
|
|
|
|
{
|
|
|
|
// this test verifies that sip taskbar is properly passed to server
|
|
|
|
QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
2016-06-13 09:32:05 +00:00
|
|
|
QVERIFY(plasmaSurfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
|
|
|
|
|
|
|
|
// verify that we got a plasma shell surface
|
2021-08-29 05:11:06 +00:00
|
|
|
auto sps = plasmaSurfaceCreatedSpy.first().first().value<PlasmaShellSurfaceInterface *>();
|
2016-06-13 09:32:05 +00:00
|
|
|
QVERIFY(sps);
|
|
|
|
QVERIFY(sps->surface());
|
|
|
|
QVERIFY(!sps->skipTaskbar());
|
|
|
|
|
|
|
|
// now change
|
|
|
|
QSignalSpy skipTaskbarChangedSpy(sps, &PlasmaShellSurfaceInterface::skipTaskbarChanged);
|
|
|
|
ps->setSkipTaskbar(true);
|
|
|
|
QVERIFY(skipTaskbarChangedSpy.wait());
|
|
|
|
QVERIFY(sps->skipTaskbar());
|
|
|
|
// setting to same again should not emit the signal
|
|
|
|
ps->setSkipTaskbar(true);
|
|
|
|
QEXPECT_FAIL("", "Should not be emitted if not changed", Continue);
|
|
|
|
QVERIFY(!skipTaskbarChangedSpy.wait(100));
|
|
|
|
QVERIFY(sps->skipTaskbar());
|
|
|
|
|
|
|
|
// setting to false should change again
|
|
|
|
ps->setSkipTaskbar(false);
|
|
|
|
QVERIFY(skipTaskbarChangedSpy.wait());
|
|
|
|
QVERIFY(!sps->skipTaskbar());
|
|
|
|
}
|
|
|
|
|
2018-05-22 12:11:22 +00:00
|
|
|
void TestPlasmaShell::testSkipSwitcher()
|
|
|
|
{
|
|
|
|
// this test verifies that Skip Switcher is properly passed to server
|
|
|
|
QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
2018-05-22 12:11:22 +00:00
|
|
|
QVERIFY(plasmaSurfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
|
|
|
|
|
|
|
|
// verify that we got a plasma shell surface
|
2021-08-29 05:11:06 +00:00
|
|
|
auto sps = plasmaSurfaceCreatedSpy.first().first().value<PlasmaShellSurfaceInterface *>();
|
2018-05-22 12:11:22 +00:00
|
|
|
QVERIFY(sps);
|
|
|
|
QVERIFY(sps->surface());
|
|
|
|
QVERIFY(!sps->skipSwitcher());
|
|
|
|
|
|
|
|
// now change
|
|
|
|
QSignalSpy skipSwitcherChangedSpy(sps, &PlasmaShellSurfaceInterface::skipSwitcherChanged);
|
|
|
|
ps->setSkipSwitcher(true);
|
|
|
|
QVERIFY(skipSwitcherChangedSpy.wait());
|
|
|
|
QVERIFY(sps->skipSwitcher());
|
|
|
|
// setting to same again should not emit the signal
|
|
|
|
ps->setSkipSwitcher(true);
|
|
|
|
QEXPECT_FAIL("", "Should not be emitted if not changed", Continue);
|
|
|
|
QVERIFY(!skipSwitcherChangedSpy.wait(100));
|
|
|
|
QVERIFY(sps->skipSwitcher());
|
|
|
|
|
|
|
|
// setting to false should change again
|
|
|
|
ps->setSkipSwitcher(false);
|
|
|
|
QVERIFY(skipSwitcherChangedSpy.wait());
|
|
|
|
QVERIFY(!sps->skipSwitcher());
|
|
|
|
}
|
|
|
|
|
2016-06-13 12:01:49 +00:00
|
|
|
void TestPlasmaShell::testPanelBehavior_data()
|
|
|
|
{
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::addColumn<KWayland::Client::PlasmaShellSurface::PanelBehavior>("client");
|
2016-06-13 12:01:49 +00:00
|
|
|
QTest::addColumn<PlasmaShellSurfaceInterface::PanelBehavior>("server");
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("autohide") << KWayland::Client::PlasmaShellSurface::PanelBehavior::AutoHide << PlasmaShellSurfaceInterface::PanelBehavior::AutoHide;
|
|
|
|
QTest::newRow("can cover") << KWayland::Client::PlasmaShellSurface::PanelBehavior::WindowsCanCover << PlasmaShellSurfaceInterface::PanelBehavior::WindowsCanCover;
|
|
|
|
QTest::newRow("go below") << KWayland::Client::PlasmaShellSurface::PanelBehavior::WindowsGoBelow << PlasmaShellSurfaceInterface::PanelBehavior::WindowsGoBelow;
|
2016-06-13 12:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPlasmaShell::testPanelBehavior()
|
|
|
|
{
|
|
|
|
// this test verifies that the panel behavior is properly passed to the server
|
|
|
|
QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
|
|
|
ps->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
|
2016-06-13 12:01:49 +00:00
|
|
|
QVERIFY(plasmaSurfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
|
|
|
|
|
|
|
|
// verify that we got a plasma shell surface
|
2021-08-29 05:11:06 +00:00
|
|
|
auto sps = plasmaSurfaceCreatedSpy.first().first().value<PlasmaShellSurfaceInterface *>();
|
2016-06-13 12:01:49 +00:00
|
|
|
QVERIFY(sps);
|
|
|
|
QVERIFY(sps->surface());
|
|
|
|
QCOMPARE(sps->panelBehavior(), PlasmaShellSurfaceInterface::PanelBehavior::AlwaysVisible);
|
|
|
|
|
|
|
|
// now change the behavior
|
|
|
|
QSignalSpy behaviorChangedSpy(sps, &PlasmaShellSurfaceInterface::panelBehaviorChanged);
|
2022-11-08 21:15:17 +00:00
|
|
|
QFETCH(KWayland::Client::PlasmaShellSurface::PanelBehavior, client);
|
2016-06-13 12:01:49 +00:00
|
|
|
ps->setPanelBehavior(client);
|
|
|
|
QVERIFY(behaviorChangedSpy.wait());
|
|
|
|
QTEST(sps->panelBehavior(), "server");
|
|
|
|
|
|
|
|
// changing to same should not trigger the signal
|
|
|
|
ps->setPanelBehavior(client);
|
|
|
|
QVERIFY(!behaviorChangedSpy.wait(100));
|
|
|
|
|
|
|
|
// but changing back to Always Visible should work
|
2022-11-08 21:15:17 +00:00
|
|
|
ps->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AlwaysVisible);
|
2016-06-13 12:01:49 +00:00
|
|
|
QVERIFY(behaviorChangedSpy.wait());
|
|
|
|
QCOMPARE(sps->panelBehavior(), PlasmaShellSurfaceInterface::PanelBehavior::AlwaysVisible);
|
|
|
|
}
|
|
|
|
|
2016-10-10 14:42:05 +00:00
|
|
|
void TestPlasmaShell::testAutoHidePanel()
|
|
|
|
{
|
|
|
|
// this test verifies that auto-hiding panels work correctly
|
|
|
|
QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
|
|
|
ps->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
|
|
|
|
ps->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AutoHide);
|
2016-10-10 14:42:05 +00:00
|
|
|
QVERIFY(plasmaSurfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
|
2021-08-29 05:11:06 +00:00
|
|
|
auto sps = plasmaSurfaceCreatedSpy.first().first().value<PlasmaShellSurfaceInterface *>();
|
2016-10-10 14:42:05 +00:00
|
|
|
QVERIFY(sps);
|
|
|
|
QCOMPARE(sps->panelBehavior(), PlasmaShellSurfaceInterface::PanelBehavior::AutoHide);
|
|
|
|
|
|
|
|
QSignalSpy autoHideRequestedSpy(sps, &PlasmaShellSurfaceInterface::panelAutoHideHideRequested);
|
|
|
|
QSignalSpy autoHideShowRequestedSpy(sps, &PlasmaShellSurfaceInterface::panelAutoHideShowRequested);
|
|
|
|
ps->requestHideAutoHidingPanel();
|
|
|
|
QVERIFY(autoHideRequestedSpy.wait());
|
|
|
|
QCOMPARE(autoHideRequestedSpy.count(), 1);
|
|
|
|
QCOMPARE(autoHideShowRequestedSpy.count(), 0);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy panelShownSpy(ps.get(), &KWayland::Client::PlasmaShellSurface::autoHidePanelShown);
|
|
|
|
QSignalSpy panelHiddenSpy(ps.get(), &KWayland::Client::PlasmaShellSurface::autoHidePanelHidden);
|
2016-10-10 14:42:05 +00:00
|
|
|
|
|
|
|
sps->hideAutoHidingPanel();
|
|
|
|
QVERIFY(panelHiddenSpy.wait());
|
|
|
|
QCOMPARE(panelHiddenSpy.count(), 1);
|
|
|
|
QCOMPARE(panelShownSpy.count(), 0);
|
|
|
|
|
|
|
|
ps->requestShowAutoHidingPanel();
|
|
|
|
QVERIFY(autoHideShowRequestedSpy.wait());
|
|
|
|
QCOMPARE(autoHideRequestedSpy.count(), 1);
|
|
|
|
QCOMPARE(autoHideShowRequestedSpy.count(), 1);
|
|
|
|
|
|
|
|
sps->showAutoHidingPanel();
|
|
|
|
QVERIFY(panelShownSpy.wait());
|
|
|
|
QCOMPARE(panelHiddenSpy.count(), 1);
|
|
|
|
QCOMPARE(panelShownSpy.count(), 1);
|
|
|
|
|
|
|
|
// change panel type
|
2022-11-08 21:15:17 +00:00
|
|
|
ps->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AlwaysVisible);
|
2016-10-10 14:42:05 +00:00
|
|
|
// requesting auto hide should raise error
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy errorSpy(m_connection, &KWayland::Client::ConnectionThread::errorOccurred);
|
2016-10-10 14:42:05 +00:00
|
|
|
ps->requestHideAutoHidingPanel();
|
|
|
|
QVERIFY(errorSpy.wait());
|
|
|
|
}
|
|
|
|
|
2016-10-12 12:40:25 +00:00
|
|
|
void TestPlasmaShell::testPanelTakesFocus()
|
|
|
|
{
|
|
|
|
// this test verifies that whether a panel wants to take focus is passed through correctly
|
|
|
|
QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
2019-12-30 15:44:09 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
|
|
|
ps->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
|
2016-10-12 12:40:25 +00:00
|
|
|
QVERIFY(plasmaSurfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
|
2021-08-29 05:11:06 +00:00
|
|
|
auto sps = plasmaSurfaceCreatedSpy.first().first().value<PlasmaShellSurfaceInterface *>();
|
2019-12-30 15:44:09 +00:00
|
|
|
QSignalSpy plasmaSurfaceTakesFocusSpy(sps, &PlasmaShellSurfaceInterface::panelTakesFocusChanged);
|
|
|
|
|
2016-10-12 12:40:25 +00:00
|
|
|
QVERIFY(sps);
|
|
|
|
QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Panel);
|
|
|
|
QCOMPARE(sps->panelTakesFocus(), false);
|
|
|
|
|
|
|
|
ps->setPanelTakesFocus(true);
|
|
|
|
m_connection->flush();
|
2019-12-30 15:44:09 +00:00
|
|
|
QVERIFY(plasmaSurfaceTakesFocusSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceTakesFocusSpy.count(), 1);
|
|
|
|
QCOMPARE(sps->panelTakesFocus(), true);
|
2016-10-12 12:40:25 +00:00
|
|
|
ps->setPanelTakesFocus(false);
|
|
|
|
m_connection->flush();
|
2019-12-30 15:44:09 +00:00
|
|
|
QVERIFY(plasmaSurfaceTakesFocusSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceTakesFocusSpy.count(), 2);
|
|
|
|
QCOMPARE(sps->panelTakesFocus(), false);
|
2016-10-12 12:40:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 13:17:07 +00:00
|
|
|
void TestPlasmaShell::testDisconnect()
|
|
|
|
{
|
|
|
|
// this test verifies that a disconnect cleans up
|
|
|
|
QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
|
|
|
// create the surface
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
2016-05-19 13:17:07 +00:00
|
|
|
|
|
|
|
// and get them on the server
|
|
|
|
QVERIFY(plasmaSurfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
|
2021-08-29 05:11:06 +00:00
|
|
|
auto sps = plasmaSurfaceCreatedSpy.first().first().value<PlasmaShellSurfaceInterface *>();
|
2016-05-19 13:17:07 +00:00
|
|
|
QVERIFY(sps);
|
|
|
|
|
|
|
|
// disconnect
|
|
|
|
QSignalSpy surfaceDestroyedSpy(sps, &QObject::destroyed);
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
}
|
|
|
|
QCOMPARE(surfaceDestroyedSpy.count(), 0);
|
|
|
|
QVERIFY(surfaceDestroyedSpy.wait());
|
|
|
|
QCOMPARE(surfaceDestroyedSpy.count(), 1);
|
|
|
|
|
|
|
|
s->destroy();
|
|
|
|
ps->destroy();
|
|
|
|
m_plasmaShell->destroy();
|
|
|
|
m_compositor->destroy();
|
|
|
|
m_registry->destroy();
|
|
|
|
m_queue->destroy();
|
|
|
|
}
|
|
|
|
|
2016-06-17 13:32:31 +00:00
|
|
|
void TestPlasmaShell::testWhileDestroying()
|
|
|
|
{
|
|
|
|
// this test tries to hit a condition that a Surface gets created with an ID which was already
|
|
|
|
// used for a previous Surface. For each Surface we try to create a PlasmaShellSurface.
|
|
|
|
// Even if there was a Surface in the past with the same ID, it should create the PlasmaShellSurface
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
|
2016-06-17 13:32:31 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-06-17 13:32:31 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
|
|
|
// create ShellSurface
|
|
|
|
QSignalSpy shellSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
|
2016-06-17 13:32:31 +00:00
|
|
|
QVERIFY(shellSurfaceCreatedSpy.wait());
|
|
|
|
|
|
|
|
// now try to create more surfaces
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy clientErrorSpy(m_connection, &KWayland::Client::ConnectionThread::errorOccurred);
|
2016-06-17 13:32:31 +00:00
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
s.reset();
|
|
|
|
s.reset(m_compositor->createSurface());
|
2022-08-01 21:29:02 +00:00
|
|
|
m_plasmaShell->createSurface(s.get(), this);
|
2016-06-17 13:32:31 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
|
|
|
}
|
|
|
|
QVERIFY(clientErrorSpy.isEmpty());
|
|
|
|
QVERIFY(!clientErrorSpy.wait(100));
|
|
|
|
QVERIFY(clientErrorSpy.isEmpty());
|
|
|
|
}
|
|
|
|
|
2016-03-09 15:17:01 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestPlasmaShell)
|
|
|
|
#include "test_plasmashell.moc"
|