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"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/platform.h"
|
2017-06-28 15:20:18 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2017-06-28 15:20:18 +00:00
|
|
|
#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()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
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());
|
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()
|
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
|
|
|
|
auto window1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
auto window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window1 != window2);
|
2017-06-28 15:20:18 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), window2);
|
2017-06-28 15:20:18 +00:00
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(!workspace()->showingDesktop());
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(workspace()->activeWindow());
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), window2);
|
2017-06-28 15:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowingDesktopTest::testRestoreFocusWithDesktopWindow()
|
|
|
|
{
|
|
|
|
// first create a desktop window
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> desktopSurface(Test::createSurface());
|
|
|
|
QVERIFY(desktopSurface != nullptr);
|
|
|
|
std::unique_ptr<Test::XdgToplevel> desktopShellSurface(Test::createXdgToplevelSurface(desktopSurface.get()));
|
|
|
|
QVERIFY(desktopSurface != nullptr);
|
|
|
|
std::unique_ptr<PlasmaShellSurface> plasmaSurface(Test::waylandPlasmaShell()->createSurface(desktopSurface.get()));
|
|
|
|
QVERIFY(plasmaSurface != nullptr);
|
2017-06-28 15:20:18 +00:00
|
|
|
plasmaSurface->setRole(PlasmaShellSurface::Role::Desktop);
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
auto desktop = Test::renderAndWaitForShown(desktopSurface.get(), QSize(100, 50), Qt::blue);
|
2017-06-28 15:20:18 +00:00
|
|
|
QVERIFY(desktop);
|
|
|
|
QVERIFY(desktop->isDesktop());
|
|
|
|
|
|
|
|
// now create some windows
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
|
|
|
|
auto window1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
auto window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window1 != window2);
|
2017-06-28 15:20:18 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), window2);
|
2017-06-28 15:20:18 +00:00
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
2022-04-23 08:33:23 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), desktop);
|
2017-06-28 15:20:18 +00:00
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(!workspace()->showingDesktop());
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(workspace()->activeWindow());
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), window2);
|
2017-06-28 15:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(ShowingDesktopTest)
|
|
|
|
#include "showing_desktop_test.moc"
|