2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-06-28 15:20:18 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
|
2017-06-28 15:20:18 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2017-06-28 15:20:18 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2020-03-04 07:55:26 +00:00
|
|
|
#include "abstract_client.h"
|
2017-06-28 15:20:18 +00:00
|
|
|
#include "platform.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/plasmashell.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_showing_desktop-0");
|
|
|
|
|
|
|
|
class ShowingDesktopTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testRestoreFocus();
|
|
|
|
void testRestoreFocusWithDesktopWindow();
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowingDesktopTest::initTestCase()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<KWin::AbstractClient*>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2017-06-28 15:20:18 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2017-06-28 15:20:18 +00:00
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2021-05-08 00:08:22 +00:00
|
|
|
Test::initWaylandWorkspace();
|
2017-06-28 15:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowingDesktopTest::init()
|
|
|
|
{
|
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowingDesktopTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowingDesktopTest::testRestoreFocus()
|
|
|
|
{
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface1(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.data()));
|
2017-06-28 15:20:18 +00:00
|
|
|
auto client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue);
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface2(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.data()));
|
2017-06-28 15:20:18 +00:00
|
|
|
auto client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(client1 != client2);
|
|
|
|
|
|
|
|
QCOMPARE(workspace()->activeClient(), client2);
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(!workspace()->showingDesktop());
|
|
|
|
|
|
|
|
QVERIFY(workspace()->activeClient());
|
|
|
|
QCOMPARE(workspace()->activeClient(), client2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowingDesktopTest::testRestoreFocusWithDesktopWindow()
|
|
|
|
{
|
|
|
|
// first create a desktop window
|
|
|
|
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> desktopSurface(Test::createSurface());
|
2017-06-28 15:20:18 +00:00
|
|
|
QVERIFY(!desktopSurface.isNull());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> desktopShellSurface(Test::createXdgToplevelSurface(desktopSurface.data()));
|
2017-06-28 15:20:18 +00:00
|
|
|
QVERIFY(!desktopSurface.isNull());
|
|
|
|
QScopedPointer<PlasmaShellSurface> plasmaSurface(Test::waylandPlasmaShell()->createSurface(desktopSurface.data()));
|
|
|
|
QVERIFY(!plasmaSurface.isNull());
|
|
|
|
plasmaSurface->setRole(PlasmaShellSurface::Role::Desktop);
|
|
|
|
|
|
|
|
auto desktop = Test::renderAndWaitForShown(desktopSurface.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(desktop);
|
|
|
|
QVERIFY(desktop->isDesktop());
|
|
|
|
|
|
|
|
// now create some windows
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface1(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.data()));
|
2017-06-28 15:20:18 +00:00
|
|
|
auto client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue);
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface2(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.data()));
|
2017-06-28 15:20:18 +00:00
|
|
|
auto client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(client1 != client2);
|
|
|
|
|
|
|
|
QCOMPARE(workspace()->activeClient(), client2);
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
QCOMPARE(workspace()->activeClient(), desktop);
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(!workspace()->showingDesktop());
|
|
|
|
|
|
|
|
QVERIFY(workspace()->activeClient());
|
|
|
|
QCOMPARE(workspace()->activeClient(), client2);
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(ShowingDesktopTest)
|
|
|
|
#include "showing_desktop_test.moc"
|