kwin/autotests/integration/outputmanagement_test.cpp

236 lines
8.9 KiB
C++
Raw Normal View History

/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2020 Méven Car <meven.car@enioka.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kwin_wayland_test.h"
#include "abstract_client.h"
#include "abstract_wayland_output.h"
#include "deleted.h"
#include "platform.h"
#include "screens.h"
#include "wayland_server.h"
#include "workspace.h"
#include <KWayland/Client/output.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/surface.h>
#include <KWaylandServer/outputconfiguration_v2_interface.h>
#include <KWaylandServer/outputdevice_v2_interface.h>
#include <KWaylandServer/outputmanagement_v2_interface.h>
#include <KWaylandServer/display.h>
using namespace KWin;
using namespace KWayland::Client;
static const QString s_socketName = QStringLiteral("wayland_test_kwin_outputmanagement-0");
class TestOutputManagement : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void testOutputDeviceDisabled();
void testOutputDeviceRemoved();
};
void TestOutputManagement::initTestCase()
{
qRegisterMetaType<KWin::Deleted*>();
qRegisterMetaType<KWin::AbstractClient*>();
qRegisterMetaType<KWin::AbstractOutput*>();
qRegisterMetaType<AbstractOutput *>();
qRegisterMetaType<KWin::AbstractOutput*>("AbstractOutput *");
qRegisterMetaType<KWayland::Client::Output*>();
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
QVERIFY(applicationStartedSpy.isValid());
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
QVERIFY(waylandServer()->init(s_socketName));
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
kwinApp()->start();
QVERIFY(applicationStartedSpy.wait());
const auto outputs = kwinApp()->platform()->enabledOutputs();
QCOMPARE(outputs.count(), 2);
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
Test::initWaylandWorkspace();
}
void TestOutputManagement::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::OutputManagementV2 |
Test::AdditionalWaylandInterface::OutputDeviceV2));
workspace()->setActiveOutput(QPoint(640, 512));
//put mouse in the middle of screen one
2021-08-28 18:40:12 +00:00
KWin::Cursors::self()->mouse()->setPos(QPoint(640, 512));
}
void TestOutputManagement::cleanup()
{
Test::destroyWaylandConnection();
}
void TestOutputManagement::testOutputDeviceDisabled()
{
// This tests checks that OutputConfiguration::apply aka Platform::requestOutputsChange works as expected
// when disabling and enabling virtual OutputDevice
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
auto size = QSize(200,200);
QSignalSpy outputEnteredSpy(surface.data(), &KWayland::Client::Surface::outputEntered);
QSignalSpy outputLeftSpy(surface.data(), &KWayland::Client::Surface::outputLeft);
QSignalSpy outputEnabledSpy(kwinApp()->platform(), &Platform::outputEnabled);
QSignalSpy outputDisabledSpy(kwinApp()->platform(), &Platform::outputDisabled);
auto c = Test::renderAndWaitForShown(surface.data(), size, Qt::blue);
//move to be in the first screen
Rework async geometry updates Window management features were written with synchronous geometry updates in mind. Currently, this poses a big problem on Wayland because geometry updates are done in asynchronous fashion there. At the moment, geometry is updated in a so called pseudo-asynchronous fashion, meaning that the frame geometry will be reset to the old value once geometry updates are unblocked. The main drawback of this approach is that it is too error prone, the data flow is hard to comprehend, etc. It is worth noting that there is already a machinery to perform async geometry which is used during interactive move/resize operations. This change extends the move/resize geometry usage beyond interactive move/resize to make asynchronous geometry updates less error prone and easier to comprehend. With the proposed solution, all geometry updates must be done on the move/resize geometry first. After that, the new geometry is passed on to the Client-specific implementation of moveResizeInternal(). To be more specific, the frameGeometry() returns the current frame geometry, it is primarily useful only to the scene. If you want to move or resize a window, you need to use moveResizeGeometry() because it corresponds to the last requested frame geometry. It is worth noting that the moveResizeGeometry() returns the desired bounding geometry. The client may commit the xdg_toplevel surface with a slightly smaller window geometry, for example to enforce a specific aspect ratio. The client is not allowed to resize beyond the size as indicated in moveResizeGeometry(). The data flow is very simple: moveResize() updates the move/resize geometry and calls the client-specific implementation of the moveResizeInternal() method. Based on whether a configure event is needed, moveResizeInternal() will update the frameGeometry() either immediately or after the client commits a new buffer. Unfortunately, both the compositor and xdg-shell clients try to update the window geometry. It means that it's possible to have conflicts between the two. With this change, the compositor's move resize geometry will be synced only if there are no pending configure events, meaning that the user doesn't try to resize the window.
2021-04-30 18:26:09 +00:00
c->moveResize(QRect(QPoint(100,100), size));
//we don't don't know where the compositor first placed this window,
//this might fire, it might not
outputEnteredSpy.wait(5);
outputEnteredSpy.clear();
QCOMPARE(waylandServer()->display()->outputs().count(), 2);
QCOMPARE(surface->outputs().count(), 1);
Output *firstOutput = surface->outputs().first();
QCOMPARE(firstOutput->globalPosition(), QPoint(0,0));
QSignalSpy modesChangedSpy(firstOutput, &Output::modeChanged);
QSignalSpy screenChangedSpy(screens(), &KWin::Screens::changed);
Test::WaylandOutputManagementV2 *outManagement = Test::waylandOutputManagementV2();
auto outputDevices = Test::waylandOutputDevicesV2();
QCOMPARE(outputDevices.count(), 2);
Test::WaylandOutputDeviceV2 *device = outputDevices.first();
QCOMPARE(device->enabled(), true);
QSignalSpy outputDeviceEnabledChangedSpy(device, &Test::WaylandOutputDeviceV2::enabledChanged);
Test::WaylandOutputConfigurationV2 *config;
// Disables an output
config = outManagement->createConfiguration();
QSignalSpy configAppliedSpy(config, &Test::WaylandOutputConfigurationV2::applied);
config->enable(device->object(), false);
config->apply();
QVERIFY(configAppliedSpy.wait());
QCOMPARE(outputDeviceEnabledChangedSpy.count(), 1);
QCOMPARE(device->enabled(), false);
QCOMPARE(screenChangedSpy.count(), 3);
QCOMPARE(outputLeftSpy.count(), 1);
QCOMPARE(outputEnteredSpy.count(), 1); // surface was moved to other screen
QCOMPARE(surface->outputs().count(), 1);
QCOMPARE(screens()->count(), 1);
QCOMPARE(modesChangedSpy.count(), 0);
QCOMPARE(outputEnabledSpy.count(), 0);
QCOMPARE(outputDisabledSpy.count(), 1);
screenChangedSpy.clear();
outputLeftSpy.clear();
outputEnteredSpy.clear();
outputDeviceEnabledChangedSpy.clear();
outputEnabledSpy.clear();
outputDisabledSpy.clear();
// Enable the disabled output
config = outManagement->createConfiguration();
QSignalSpy configAppliedSpy2(config, &Test::WaylandOutputConfigurationV2::applied);
config->enable(device->object(), true);
config->apply();
QVERIFY(configAppliedSpy2.wait());
QVERIFY(outputEnteredSpy.wait());
QCOMPARE(outputDeviceEnabledChangedSpy.count(), 1);
QCOMPARE(device->enabled(), true);
QCOMPARE(screenChangedSpy.count(), 3);
QCOMPARE(outputLeftSpy.count(), 1);
QCOMPARE(outputEnteredSpy.count(), 1); // surface moved back to first screen
QCOMPARE(surface->outputs().count(), 1);
QCOMPARE(screens()->count(), 2);
QCOMPARE(modesChangedSpy.count(), 0);
QCOMPARE(outputEnabledSpy.count(), 1);
QCOMPARE(outputDisabledSpy.count(), 0);
}
void TestOutputManagement::testOutputDeviceRemoved()
{
// This tests checks that OutputConfiguration::apply aka Platform::requestOutputsChange works as expected
// when removing a virtual OutputDevice
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
auto size = QSize(200,200);
QSignalSpy outputEnteredSpy(surface.data(), &KWayland::Client::Surface::outputEntered);
QSignalSpy outputLeftSpy(surface.data(), &KWayland::Client::Surface::outputLeft);
QSignalSpy outputEnabledSpy(kwinApp()->platform(), &Platform::outputEnabled);
QSignalSpy outputDisabledSpy(kwinApp()->platform(), &Platform::outputDisabled);
QSignalSpy outputRemovedSpy(kwinApp()->platform(), &Platform::outputRemoved);
auto c = Test::renderAndWaitForShown(surface.data(), size, Qt::blue);
//move to be in the first screen
c->move(QPoint(100,100));
//we don't don't know where the compositor first placed this window,
//this might fire, it might not
outputEnteredSpy.wait(5);
outputEnteredSpy.clear();
QCOMPARE(waylandServer()->display()->outputs().count(), 2);
QCOMPARE(surface->outputs().count(), 1);
Output *firstOutput = surface->outputs().first();
QCOMPARE(firstOutput->globalPosition(), QPoint(0,0));
QSignalSpy modesChangedSpy(firstOutput, &Output::modeChanged);
QSignalSpy screenChangedSpy(screens(), &KWin::Screens::changed);
QCOMPARE(Test::waylandOutputDevicesV2().count(), 2);
Test::WaylandOutputDeviceV2 *device = Test::waylandOutputDevicesV2().first();
QCOMPARE(device->enabled(), true);
QSignalSpy outputDeviceEnabledChangedSpy(device, &Test::WaylandOutputDeviceV2::enabledChanged);
AbstractOutput *output = kwinApp()->platform()->outputs().first();
// Removes an output
QMetaObject::invokeMethod(kwinApp()->platform(), "removeOutput", Qt::DirectConnection, Q_ARG(AbstractOutput *, output));
// Let the new state propagate
QVERIFY(outputEnteredSpy.wait());
QCOMPARE(waylandServer()->display()->outputs().count(), 1);
QCOMPARE(waylandServer()->display()->outputDevices().count(), 1);
QCOMPARE(Test::waylandOutputDevicesV2().count(), 1);
QCOMPARE(outputDeviceEnabledChangedSpy.count(), 1);
QCOMPARE(device->enabled(), false);
QCOMPARE(outputLeftSpy.count(), 1);
QCOMPARE(outputEnteredSpy.count(), 1); // surface moved to the other screen
QCOMPARE(surface->outputs().count(), 1);
QCOMPARE(screens()->count(), 1);
QCOMPARE(screenChangedSpy.count(), 3);
QCOMPARE(modesChangedSpy.count(), 0);
QCOMPARE(outputEnabledSpy.count(), 0);
QCOMPARE(outputDisabledSpy.count(), 1);
QCOMPARE(outputRemovedSpy.count(), 1);
}
WAYLANDTEST_MAIN(TestOutputManagement)
#include "outputmanagement_test.moc"