kwin/autotests/integration/workspace_test.cpp
Vlad Zahorodnii 02fbeeae78 Make Workspace::desktopResized() reassign outputs of uninitialized windows
If an output is deleted, the Workspace::desktopResized() is going to
re-assign windows to the new outputs. It is done so so the workspace
re-arrangement procedure is deterministic and has concrete order.

However, with the current Window lifecycle management, it's possible
to encounter the follwing case:

- xdg_toplevel gets created on output A
- xdg_toplevel initial state is committed
- output A is removed
- a wl_buffer is attached to the xdg_toplevel, which results in a
  geometry change and an output change
- Window::setMoveResizeOutput() is called, but the previous output
  is a dangling pointer

CCBUG: 489632
2024-07-23 13:46:06 +00:00

115 lines
3.6 KiB
C++

/*
SPDX-FileCopyrightText: 2024 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kwin_wayland_test.h"
#include "core/outputconfiguration.h"
#include "pointer_input.h"
#include "wayland_server.h"
#include "workspace.h"
#include <KWayland/Client/surface.h>
using namespace KWin;
static const QString s_socketName = QStringLiteral("wayland_test_kwin_workspace-0");
class WorkspaceTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void evacuateMappedWindowFromRemovedOutput();
void evacuateUnmappedWindowFromRemovedOutput();
};
void WorkspaceTest::initTestCase()
{
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
QVERIFY(waylandServer()->init(s_socketName));
kwinApp()->start();
QVERIFY(applicationStartedSpy.wait());
}
void WorkspaceTest::init()
{
Test::setOutputConfig({
QRect(0, 0, 1280, 1024),
QRect(1280, 0, 1280, 1024),
});
QVERIFY(Test::setupWaylandConnection());
workspace()->setActiveOutput(QPoint(640, 512));
input()->pointer()->warp(QPoint(640, 512));
}
void WorkspaceTest::cleanup()
{
Test::destroyWaylandConnection();
}
void WorkspaceTest::evacuateMappedWindowFromRemovedOutput()
{
// This test verifies that a window will be evacuated to another output if the output it is
// currently on has been either removed or disabled.
const auto firstOutput = workspace()->outputs()[0];
const auto secondOutput = workspace()->outputs()[1];
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);
QCOMPARE(window->output(), firstOutput);
QCOMPARE(window->moveResizeOutput(), firstOutput);
QSignalSpy outputChangedSpy(window, &Window::outputChanged);
{
OutputConfiguration config;
config.changeSet(firstOutput)->enabled = false;
workspace()->applyOutputConfiguration(config);
}
QCOMPARE(outputChangedSpy.count(), 1);
QCOMPARE(window->output(), secondOutput);
QCOMPARE(window->moveResizeOutput(), secondOutput);
}
void WorkspaceTest::evacuateUnmappedWindowFromRemovedOutput()
{
// This test verifies that a window, which is not fully managed by the Workspace yet, will be
// evacuated to another output if the output it is currently on has been withdrawn.
const auto firstOutput = workspace()->outputs()[0];
const auto secondOutput = workspace()->outputs()[1];
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly));
surface->commit(KWayland::Client::Surface::CommitFlag::None);
QVERIFY(Test::waylandSync());
QCOMPARE(waylandServer()->windows().count(), 1);
Window *window = waylandServer()->windows().constFirst();
QVERIFY(!window->readyForPainting());
QCOMPARE(window->output(), firstOutput);
QCOMPARE(window->moveResizeOutput(), firstOutput);
QSignalSpy outputChangedSpy(window, &Window::outputChanged);
{
OutputConfiguration config;
config.changeSet(firstOutput)->enabled = false;
workspace()->applyOutputConfiguration(config);
}
QCOMPARE(outputChangedSpy.count(), 1);
QCOMPARE(window->output(), secondOutput);
QCOMPARE(window->moveResizeOutput(), secondOutput);
}
WAYLANDTEST_MAIN(WorkspaceTest)
#include "workspace_test.moc"