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
|
|
|
|
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/surface.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
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();
|
2024-01-15 09:44:09 +00:00
|
|
|
void testQuitAfterActivatingHiddenWindow();
|
|
|
|
void testDontQuitAfterActivatingDock();
|
2024-01-15 09:52:04 +00:00
|
|
|
void testQuitAfterAddingWindow();
|
|
|
|
void testDontQuitAfterAddingDock();
|
2017-06-28 15:20:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
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()
|
|
|
|
{
|
2023-05-23 11:35:49 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::LayerShellV1));
|
2017-06-28 15:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2023-05-23 11:35:49 +00:00
|
|
|
std::unique_ptr<Test::LayerSurfaceV1> desktopShellSurface(Test::createLayerSurfaceV1(desktopSurface.get(), QStringLiteral("desktop")));
|
2023-10-26 14:03:27 +00:00
|
|
|
desktopShellSurface->set_keyboard_interactivity(1);
|
2023-05-23 11:35:49 +00:00
|
|
|
desktopShellSurface->set_layer(Test::LayerShellV1::layer_background);
|
|
|
|
desktopShellSurface->set_size(0, 0);
|
|
|
|
desktopShellSurface->set_exclusive_zone(-1);
|
|
|
|
desktopShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom
|
|
|
|
| Test::LayerSurfaceV1::anchor_top
|
|
|
|
| Test::LayerSurfaceV1::anchor_left
|
|
|
|
| Test::LayerSurfaceV1::anchor_right);
|
|
|
|
desktopSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QSignalSpy desktopConfigureRequestedSpy(desktopShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
|
|
|
|
QVERIFY(desktopConfigureRequestedSpy.wait());
|
|
|
|
auto desktop = Test::renderAndWaitForShown(desktopSurface.get(), desktopConfigureRequestedSpy.last().at(1).toSize(), 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
|
|
|
}
|
|
|
|
|
2024-01-15 09:44:09 +00:00
|
|
|
void ShowingDesktopTest::testQuitAfterActivatingHiddenWindow()
|
|
|
|
{
|
|
|
|
// This test verifies that the show desktop mode is deactivated after activating a hidden window.
|
|
|
|
|
|
|
|
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);
|
|
|
|
QCOMPARE(workspace()->activeWindow(), window2);
|
|
|
|
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
|
|
|
|
workspace()->activateWindow(window1);
|
|
|
|
QVERIFY(!workspace()->showingDesktop());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowingDesktopTest::testDontQuitAfterActivatingDock()
|
|
|
|
{
|
|
|
|
// This test verifies that activating windows belonging to desktop doesn't break showing desktop mode.
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> desktopSurface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::LayerSurfaceV1> desktopShellSurface(Test::createLayerSurfaceV1(desktopSurface.get(), QStringLiteral("desktop")));
|
|
|
|
desktopShellSurface->set_keyboard_interactivity(1);
|
|
|
|
desktopShellSurface->set_layer(Test::LayerShellV1::layer_background);
|
|
|
|
desktopShellSurface->set_size(0, 0);
|
|
|
|
desktopShellSurface->set_exclusive_zone(-1);
|
|
|
|
desktopShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom
|
|
|
|
| Test::LayerSurfaceV1::anchor_top
|
|
|
|
| Test::LayerSurfaceV1::anchor_left
|
|
|
|
| Test::LayerSurfaceV1::anchor_right);
|
|
|
|
desktopSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QSignalSpy desktopConfigureRequestedSpy(desktopShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
|
|
|
|
QVERIFY(desktopConfigureRequestedSpy.wait());
|
|
|
|
auto desktop = Test::renderAndWaitForShown(desktopSurface.get(), desktopConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> dockSurface{Test::createSurface()};
|
|
|
|
std::unique_ptr<Test::LayerSurfaceV1> dockShellSurface{Test::createLayerSurfaceV1(dockSurface.get(), QStringLiteral("dock"))};
|
|
|
|
dockShellSurface->set_size(1280, 50);
|
|
|
|
dockShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom);
|
|
|
|
dockShellSurface->set_exclusive_zone(50);
|
|
|
|
dockShellSurface->set_keyboard_interactivity(1);
|
|
|
|
dockSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QSignalSpy dockConfigureRequestedSpy(dockShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
|
|
|
|
QVERIFY(dockConfigureRequestedSpy.wait());
|
|
|
|
auto dock = Test::renderAndWaitForShown(dockSurface.get(), dockConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
QVERIFY(desktop->isActive());
|
|
|
|
|
|
|
|
workspace()->activateWindow(dock);
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
QVERIFY(dock->isActive());
|
|
|
|
|
|
|
|
workspace()->activateWindow(desktop);
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
QVERIFY(desktop->isActive());
|
|
|
|
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(!workspace()->showingDesktop());
|
|
|
|
}
|
|
|
|
|
2024-01-15 09:52:04 +00:00
|
|
|
void ShowingDesktopTest::testQuitAfterAddingWindow()
|
|
|
|
{
|
|
|
|
// This test verifies that the show desktop mode is deactivated after mapping a new window.
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
|
|
|
|
Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
|
|
|
|
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
|
|
|
|
|
|
|
|
QVERIFY(!workspace()->showingDesktop());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowingDesktopTest::testDontQuitAfterAddingDock()
|
|
|
|
{
|
|
|
|
// This test verifies that the show desktop mode is not broken after adding a dock.
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> dockSurface{Test::createSurface()};
|
|
|
|
std::unique_ptr<Test::LayerSurfaceV1> dockShellSurface{Test::createLayerSurfaceV1(dockSurface.get(), QStringLiteral("dock"))};
|
|
|
|
dockShellSurface->set_size(1280, 50);
|
|
|
|
dockShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom);
|
|
|
|
dockShellSurface->set_exclusive_zone(50);
|
|
|
|
dockShellSurface->set_keyboard_interactivity(1);
|
|
|
|
dockSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QSignalSpy dockConfigureRequestedSpy(dockShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
|
|
|
|
QVERIFY(dockConfigureRequestedSpy.wait());
|
|
|
|
auto dock = Test::renderAndWaitForShown(dockSurface.get(), dockConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
|
|
|
|
QVERIFY(dock->isActive());
|
|
|
|
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
}
|
|
|
|
|
2017-06-28 15:20:18 +00:00
|
|
|
WAYLANDTEST_MAIN(ShowingDesktopTest)
|
|
|
|
#include "showing_desktop_test.moc"
|