2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-10-02 13:04:57 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-10-02 13:04:57 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-10-02 13:04:57 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2021-02-09 18:18:36 +00:00
|
|
|
|
Make backends part of libkwin
Platform backends are provided as plugins. This is great for
extensibility, but the disadvantages of this design outweigh the
benefits.
The number of backends will be limited, it's safe to say that we will
have to maintain three backends for many years to come - kms/drm,
virtual, and wayland. The plugin system adds unnecessary complexity.
Startup logic is affected too. At the moment, platform backends provide
the session object, which is awkward as it starts adding dependencies
between backends. It will be nicer if the session is created depending
on the loaded session type.
In some cases, wayland code needs to talk to the backend directly, e.g.
for drm leasing, etc. With the plugin architecture it's hard to do that.
Not impossible though, we can approach it as in Qt 6, but it's still
harder than linking the code directly.
Of course, the main disadvantage of shipping backends in a lib is that
you will need to patch kwin if you need a custom platform, however such
cases will be rare.
Despite that disadvantage, I still think that it's a step in the right
direction where the goal is to have multi-purpose backends and other
reusable components of kwin.
The legacy X11 standalone platform is linked directly to kwin_x11
executable, while the remaining backends are linked to libkwin.
2022-07-22 14:22:09 +00:00
|
|
|
#include "backends/virtual/virtual_backend.h"
|
2023-08-31 12:44:50 +00:00
|
|
|
#include "compositor_wayland.h"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/session.h"
|
2023-11-20 14:53:25 +00:00
|
|
|
#include "effect/effecthandler.h"
|
2021-02-09 18:18:36 +00:00
|
|
|
#include "inputmethod.h"
|
2022-08-31 20:29:15 +00:00
|
|
|
#include "placement.h"
|
2021-02-09 18:18:36 +00:00
|
|
|
#include "pluginmanager.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "utils/xcbutils.h"
|
2021-02-09 18:18:36 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
2022-04-22 10:09:02 +00:00
|
|
|
#include "xwayland/xwayland.h"
|
2023-01-27 12:29:32 +00:00
|
|
|
#include "xwayland/xwaylandlauncher.h"
|
2015-10-02 13:04:57 +00:00
|
|
|
|
2016-04-06 15:30:00 +00:00
|
|
|
#include <KPluginMetaData>
|
|
|
|
|
2015-10-02 13:04:57 +00:00
|
|
|
#include <QAbstractEventDispatcher>
|
|
|
|
#include <QPluginLoader>
|
|
|
|
#include <QSocketNotifier>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
|
|
|
|
// system
|
|
|
|
#include <iostream>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <unistd.h>
|
2015-10-02 13:04:57 +00:00
|
|
|
|
2020-11-20 14:28:47 +00:00
|
|
|
Q_IMPORT_PLUGIN(KWinIntegrationPlugin)
|
2023-11-20 22:28:23 +00:00
|
|
|
#if KWIN_BUILD_GLOBALSHORTCUTS
|
2020-11-21 10:16:59 +00:00
|
|
|
Q_IMPORT_PLUGIN(KGlobalAccelImpl)
|
2023-11-20 22:28:23 +00:00
|
|
|
#endif
|
2020-11-21 10:22:48 +00:00
|
|
|
Q_IMPORT_PLUGIN(KWindowSystemKWinPlugin)
|
2020-11-21 10:36:49 +00:00
|
|
|
Q_IMPORT_PLUGIN(KWinIdleTimePoller)
|
2020-11-20 14:28:47 +00:00
|
|
|
|
2015-10-02 13:04:57 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2017-09-30 14:35:52 +00:00
|
|
|
WaylandTestApplication::WaylandTestApplication(OperationMode mode, int &argc, char **argv)
|
2022-07-15 07:15:54 +00:00
|
|
|
: Application(mode, argc, argv)
|
2015-10-02 13:04:57 +00:00
|
|
|
{
|
2016-10-05 11:21:33 +00:00
|
|
|
QStandardPaths::setTestModeEnabled(true);
|
2023-11-23 08:25:15 +00:00
|
|
|
|
|
|
|
const QStringList configs{
|
|
|
|
QStringLiteral("kaccessrc"),
|
|
|
|
QStringLiteral("kglobalshortcutsrc"),
|
|
|
|
};
|
|
|
|
for (const QString &config : configs) {
|
|
|
|
if (const QString &fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, config); !fileName.isEmpty()) {
|
|
|
|
QFile::remove(fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 17:17:53 +00:00
|
|
|
QIcon::setThemeName(QStringLiteral("breeze"));
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_ACTIVITIES
|
2015-12-18 15:40:52 +00:00
|
|
|
setUseKActivities(false);
|
|
|
|
#endif
|
2016-02-12 14:22:55 +00:00
|
|
|
qputenv("KWIN_COMPOSE", QByteArrayLiteral("Q"));
|
2021-05-05 06:15:17 +00:00
|
|
|
qputenv("XDG_CURRENT_DESKTOP", QByteArrayLiteral("KDE"));
|
2018-11-07 15:09:34 +00:00
|
|
|
qunsetenv("XKB_DEFAULT_RULES");
|
|
|
|
qunsetenv("XKB_DEFAULT_MODEL");
|
|
|
|
qunsetenv("XKB_DEFAULT_LAYOUT");
|
|
|
|
qunsetenv("XKB_DEFAULT_VARIANT");
|
|
|
|
qunsetenv("XKB_DEFAULT_OPTIONS");
|
2018-12-06 17:38:36 +00:00
|
|
|
|
2021-11-29 07:53:53 +00:00
|
|
|
auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
2023-11-27 13:11:22 +00:00
|
|
|
KConfigGroup windowsGroup = config->group(QStringLiteral("Windows"));
|
2022-08-31 20:29:15 +00:00
|
|
|
windowsGroup.writeEntry("Placement", Placement::policyToString(PlacementSmart));
|
2021-11-29 07:53:53 +00:00
|
|
|
windowsGroup.sync();
|
|
|
|
setConfig(config);
|
|
|
|
|
2018-12-06 17:38:36 +00:00
|
|
|
const auto ownPath = libraryPaths().last();
|
|
|
|
removeLibraryPath(ownPath);
|
|
|
|
addLibraryPath(ownPath);
|
|
|
|
|
2022-07-23 13:22:54 +00:00
|
|
|
setSession(Session::create(Session::Type::Noop));
|
2022-11-05 10:43:41 +00:00
|
|
|
setOutputBackend(std::make_unique<VirtualBackend>());
|
2016-04-06 15:30:00 +00:00
|
|
|
WaylandServer::create(this);
|
2018-08-22 00:20:16 +00:00
|
|
|
setProcessStartupEnvironment(QProcessEnvironment::systemEnvironment());
|
2015-10-02 13:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WaylandTestApplication::~WaylandTestApplication()
|
|
|
|
{
|
2019-01-06 16:05:10 +00:00
|
|
|
setTerminating();
|
2015-11-12 10:29:56 +00:00
|
|
|
// need to unload all effects prior to destroying X connection as they might do X calls
|
2016-07-04 12:37:35 +00:00
|
|
|
// also before destroy Workspace, as effects might call into Workspace
|
2015-11-12 10:29:56 +00:00
|
|
|
if (effects) {
|
2023-11-15 09:51:56 +00:00
|
|
|
effects->unloadAllEffects();
|
2015-11-12 10:29:56 +00:00
|
|
|
}
|
2022-08-03 10:31:27 +00:00
|
|
|
m_xwayland.reset();
|
2022-02-26 08:22:31 +00:00
|
|
|
destroyVirtualInputDevices();
|
2022-07-23 12:39:17 +00:00
|
|
|
destroyColorManager();
|
wayland: Terminate client connections before Workspace is destroyed
Summary:
When ShellClient tears down, it needs to access RuleBook in order to
discard temporary rules. The problem is that WaylandServer outlives
Workspace and therefore so does ShellClient.
We can't guard against the case when RuleBook::self() is nullptr as it
is vital to discard temporary rules.
This change adjusts termination sequence so all shell clients are
destroyed before Workspace(and thus RuleBook) is gone.
ASAN output:
==19922==ERROR: AddressSanitizer: heap-use-after-free on address 0x606000142060 at pc 0x7fbc0fb878bb bp 0x7ffd7d464520 sp 0x7ffd7d464518
READ of size 8 at 0x606000142060 thread T0
#0 0x7fbc0fb878ba in QList<KWin::Rules*>::detach() /usr/include/qt5/QtCore/qlist.h:172
#1 0x7fbc0fb8538d in QList<KWin::Rules*>::begin() /usr/include/qt5/QtCore/qlist.h:324
#2 0x7fbc0fb808b6 in KWin::RuleBook::discardUsed(KWin::AbstractClient*, bool) /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/rules.cpp:1144
#3 0x7fbc0fe36e32 in KWin::ShellClient::destroyClient() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/shell_client.cpp:435
#4 0x7fbc0fe7a726 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (KWin::ShellClient::*)()>::call(void (KWin::ShellClient::*)(), KWin::ShellClient*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:152
#5 0x7fbc0fe784c3 in void QtPrivate::FunctionPointer<void (KWin::ShellClient::*)()>::call<QtPrivate::List<>, void>(void (KWin::ShellClient::*)(), KWin::ShellClient*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:185
#6 0x7fbc0fe74de9 in QtPrivate::QSlotObject<void (KWin::ShellClient::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (/home/jenkins/install-prefix/lib64/libkwin.so.5+0x1677de9)
#7 0x7fbc04f27357 in QMetaObject::activate(QObject*, int, int, void**) (/usr/lib64/libQt5Core.so.5+0x2b3357)
#8 0x7fbc074e1970 in KWayland::Server::Resource::unbound() /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/build/src/server/KF5WaylandServer_autogen/EWIEGA46WW/moc_resource.cpp:142
#9 0x7fbc0766b4b4 in KWayland::Server::Resource::Private::unbind(wl_resource*) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/resource.cpp:68
#10 0x7fbc00bdc2ae (/usr/lib64/libwayland-server.so.0+0x92ae)
#11 0x7fbc00bdc32f in wl_resource_destroy (/usr/lib64/libwayland-server.so.0+0x932f)
#12 0x7fbc0766b53f in KWayland::Server::Resource::Private::resourceDestroyedCallback(wl_client*, wl_resource*) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/resource.cpp:76
#13 0x7fbbff481d8c (/usr/lib64/libffi.so.7+0x6d8c)
#14 0x7fbbff481179 (/usr/lib64/libffi.so.7+0x6179)
#15 0x7fbc00bdfa5f (/usr/lib64/libwayland-server.so.0+0xca5f)
#16 0x7fbc00bdc6d1 (/usr/lib64/libwayland-server.so.0+0x96d1)
#17 0x7fbc00bddc71 in wl_event_loop_dispatch (/usr/lib64/libwayland-server.so.0+0xac71)
#18 0x7fbc07541e50 in KWayland::Server::Display::Private::dispatch() /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/display.cpp:148
#19 0x7fbc075432de in KWayland::Server::Display::dispatchEvents(int) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/display.cpp:220
#20 0x7fbc0fe864ca in KWin::WaylandServer::dispatch() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/wayland_server.cpp:616
#21 0x451ce0 in KWin::WaylandTestApplication::~WaylandTestApplication() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/autotests/integration/kwin_wayland_test.cpp:91
#22 0x42faa1 in main /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/autotests/integration/globalshortcuts_test.cpp:381
#23 0x7fbc04796bca in __libc_start_main (/lib64/libc.so.6+0x26bca)
#24 0x413ea9 in _start (/home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/build/bin/testGlobalShortcuts+0x413ea9)
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22821
2019-07-30 08:40:18 +00:00
|
|
|
destroyWorkspace();
|
2021-10-14 07:40:08 +00:00
|
|
|
destroyInputMethod();
|
2015-11-10 07:52:40 +00:00
|
|
|
destroyCompositor();
|
2021-10-14 19:03:39 +00:00
|
|
|
destroyInput();
|
2015-10-02 13:04:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 08:22:31 +00:00
|
|
|
void WaylandTestApplication::createVirtualInputDevices()
|
|
|
|
{
|
2023-08-10 16:53:37 +00:00
|
|
|
m_virtualKeyboard = std::make_unique<Test::VirtualInputDevice>();
|
2022-02-26 08:22:31 +00:00
|
|
|
m_virtualKeyboard->setName(QStringLiteral("Virtual Keyboard 1"));
|
|
|
|
m_virtualKeyboard->setKeyboard(true);
|
|
|
|
|
2023-08-10 16:53:37 +00:00
|
|
|
m_virtualPointer = std::make_unique<Test::VirtualInputDevice>();
|
2022-02-26 08:22:31 +00:00
|
|
|
m_virtualPointer->setName(QStringLiteral("Virtual Pointer 1"));
|
|
|
|
m_virtualPointer->setPointer(true);
|
|
|
|
|
2023-08-10 16:53:37 +00:00
|
|
|
m_virtualTouch = std::make_unique<Test::VirtualInputDevice>();
|
2022-02-26 08:22:31 +00:00
|
|
|
m_virtualTouch->setName(QStringLiteral("Virtual Touch 1"));
|
|
|
|
m_virtualTouch->setTouch(true);
|
|
|
|
|
|
|
|
input()->addInputDevice(m_virtualPointer.get());
|
|
|
|
input()->addInputDevice(m_virtualTouch.get());
|
|
|
|
input()->addInputDevice(m_virtualKeyboard.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandTestApplication::destroyVirtualInputDevices()
|
|
|
|
{
|
2023-04-15 20:50:33 +00:00
|
|
|
if (m_virtualPointer) {
|
|
|
|
input()->removeInputDevice(m_virtualPointer.get());
|
|
|
|
}
|
|
|
|
if (m_virtualTouch) {
|
|
|
|
input()->removeInputDevice(m_virtualTouch.get());
|
|
|
|
}
|
|
|
|
if (m_virtualKeyboard) {
|
|
|
|
input()->removeInputDevice(m_virtualKeyboard.get());
|
|
|
|
}
|
2022-02-26 08:22:31 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 13:04:57 +00:00
|
|
|
void WaylandTestApplication::performStartup()
|
|
|
|
{
|
2020-09-01 08:58:46 +00:00
|
|
|
if (!m_inputMethodServerToStart.isEmpty()) {
|
2022-07-20 10:14:27 +00:00
|
|
|
createInputMethod();
|
2020-09-01 08:58:46 +00:00
|
|
|
if (m_inputMethodServerToStart != QStringLiteral("internal")) {
|
2022-07-20 10:14:27 +00:00
|
|
|
inputMethod()->setInputMethodCommand(m_inputMethodServerToStart);
|
|
|
|
inputMethod()->setEnabled(true);
|
2020-09-01 08:58:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 13:04:57 +00:00
|
|
|
// first load options - done internally by a different thread
|
|
|
|
createOptions();
|
2022-11-05 10:43:41 +00:00
|
|
|
if (!outputBackend()->initialize()) {
|
2021-01-30 13:22:07 +00:00
|
|
|
std::exit(1);
|
|
|
|
}
|
2015-10-02 13:04:57 +00:00
|
|
|
|
|
|
|
// try creating the Wayland Backend
|
|
|
|
createInput();
|
2022-02-26 08:22:31 +00:00
|
|
|
createVirtualInputDevices();
|
2023-09-13 15:15:04 +00:00
|
|
|
createTabletModeManager();
|
2015-10-02 13:04:57 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
WaylandCompositor::create();
|
2023-09-14 12:07:54 +00:00
|
|
|
createWorkspace();
|
|
|
|
createColorManager();
|
|
|
|
createPlugins();
|
|
|
|
|
2019-02-23 12:17:50 +00:00
|
|
|
connect(Compositor::self(), &Compositor::sceneCreated, this, &WaylandTestApplication::continueStartupWithScene);
|
2015-10-02 13:04:57 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 12:17:50 +00:00
|
|
|
void WaylandTestApplication::continueStartupWithScene()
|
2015-10-02 13:04:57 +00:00
|
|
|
{
|
2019-02-23 12:17:50 +00:00
|
|
|
disconnect(Compositor::self(), &Compositor::sceneCreated, this, &WaylandTestApplication::continueStartupWithScene);
|
|
|
|
|
2022-07-30 15:12:36 +00:00
|
|
|
waylandServer()->initWorkspace();
|
|
|
|
|
2020-07-07 09:45:55 +00:00
|
|
|
if (!waylandServer()->start()) {
|
|
|
|
qFatal("Failed to initialize the Wayland server, exiting now");
|
|
|
|
}
|
|
|
|
|
2023-01-27 12:29:32 +00:00
|
|
|
if (operationMode() == OperationModeXwayland) {
|
|
|
|
m_xwayland = std::make_unique<Xwl::Xwayland>(this);
|
|
|
|
m_xwayland->init();
|
2019-02-23 12:17:50 +00:00
|
|
|
}
|
2018-08-22 00:20:16 +00:00
|
|
|
|
2023-01-27 12:29:32 +00:00
|
|
|
notifyStarted();
|
2015-10-02 13:04:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 08:22:31 +00:00
|
|
|
Test::VirtualInputDevice *WaylandTestApplication::virtualPointer() const
|
|
|
|
{
|
|
|
|
return m_virtualPointer.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Test::VirtualInputDevice *WaylandTestApplication::virtualKeyboard() const
|
|
|
|
{
|
|
|
|
return m_virtualKeyboard.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Test::VirtualInputDevice *WaylandTestApplication::virtualTouch() const
|
|
|
|
{
|
|
|
|
return m_virtualTouch.get();
|
|
|
|
}
|
2022-08-03 10:31:27 +00:00
|
|
|
|
|
|
|
XwaylandInterface *WaylandTestApplication::xwayland() const
|
|
|
|
{
|
|
|
|
return m_xwayland.get();
|
|
|
|
}
|
2022-06-30 22:23:35 +00:00
|
|
|
|
|
|
|
Test::FractionalScaleManagerV1::~FractionalScaleManagerV1()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
Test::FractionalScaleV1::~FractionalScaleV1()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Test::FractionalScaleV1::preferredScale()
|
|
|
|
{
|
|
|
|
return m_preferredScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test::FractionalScaleV1::wp_fractional_scale_v1_preferred_scale(uint32_t scale)
|
|
|
|
{
|
|
|
|
m_preferredScale = scale;
|
|
|
|
}
|
2023-05-08 10:16:00 +00:00
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
void Test::setOutputConfig(const QList<QRect> &geometries)
|
2023-05-08 10:16:00 +00:00
|
|
|
{
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<VirtualBackend::OutputInfo> converted;
|
2023-05-08 10:16:00 +00:00
|
|
|
std::transform(geometries.begin(), geometries.end(), std::back_inserter(converted), [](const auto &geometry) {
|
|
|
|
return VirtualBackend::OutputInfo{
|
|
|
|
.geometry = geometry,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
static_cast<VirtualBackend *>(kwinApp()->outputBackend())->setVirtualOutputs(converted);
|
|
|
|
}
|
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
void Test::setOutputConfig(const QList<OutputInfo> &infos)
|
2023-05-08 10:16:00 +00:00
|
|
|
{
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<VirtualBackend::OutputInfo> converted;
|
2023-05-08 10:16:00 +00:00
|
|
|
std::transform(infos.begin(), infos.end(), std::back_inserter(converted), [](const auto &info) {
|
|
|
|
return VirtualBackend::OutputInfo{
|
|
|
|
.geometry = info.geometry,
|
|
|
|
.scale = info.scale,
|
2023-05-08 08:48:30 +00:00
|
|
|
.internal = info.internal,
|
2023-05-08 10:16:00 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
static_cast<VirtualBackend *>(kwinApp()->outputBackend())->setVirtualOutputs(converted);
|
|
|
|
}
|
2015-10-02 13:04:57 +00:00
|
|
|
}
|
2023-07-05 06:30:14 +00:00
|
|
|
|
|
|
|
#include "moc_kwin_wayland_test.cpp"
|