2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-02-09 12:28:37 +00:00
|
|
|
#include "wayland_server.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
|
|
|
#include <config-kwin.h>
|
|
|
|
|
2015-03-04 08:21:10 +00:00
|
|
|
#include "composite.h"
|
2017-11-16 20:48:19 +00:00
|
|
|
#include "idle_inhibition.h"
|
2020-09-04 07:03:04 +00:00
|
|
|
#include "inputpanelv1integration.h"
|
2021-10-02 08:26:51 +00:00
|
|
|
#include "keyboard_input.h"
|
2020-08-07 19:01:42 +00:00
|
|
|
#include "layershellv1integration.h"
|
2020-11-07 02:03:57 +00:00
|
|
|
#include "main.h"
|
2022-04-14 12:33:28 +00:00
|
|
|
#include "output.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "platform.h"
|
2022-03-28 01:40:12 +00:00
|
|
|
#include "scene.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "screens.h"
|
2020-11-04 13:35:37 +00:00
|
|
|
#include "unmanaged.h"
|
2022-01-13 14:02:41 +00:00
|
|
|
#include "utils/serviceutils.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "virtualdesktops.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/appmenu_interface.h"
|
|
|
|
#include "wayland/blur_interface.h"
|
|
|
|
#include "wayland/compositor_interface.h"
|
|
|
|
#include "wayland/datacontroldevicemanager_v1_interface.h"
|
|
|
|
#include "wayland/datadevicemanager_interface.h"
|
|
|
|
#include "wayland/datasource_interface.h"
|
|
|
|
#include "wayland/display.h"
|
|
|
|
#include "wayland/dpms_interface.h"
|
|
|
|
#include "wayland/filtered_display.h"
|
|
|
|
#include "wayland/idle_interface.h"
|
|
|
|
#include "wayland/idleinhibit_v1_interface.h"
|
|
|
|
#include "wayland/inputmethod_v1_interface.h"
|
|
|
|
#include "wayland/keyboard_shortcuts_inhibit_v1_interface.h"
|
|
|
|
#include "wayland/keystate_interface.h"
|
|
|
|
#include "wayland/linuxdmabufv1clientbuffer.h"
|
|
|
|
#include "wayland/output_interface.h"
|
|
|
|
#include "wayland/outputconfiguration_v2_interface.h"
|
|
|
|
#include "wayland/outputmanagement_v2_interface.h"
|
|
|
|
#include "wayland/plasmashell_interface.h"
|
|
|
|
#include "wayland/plasmavirtualdesktop_interface.h"
|
|
|
|
#include "wayland/plasmawindowmanagement_interface.h"
|
|
|
|
#include "wayland/pointerconstraints_v1_interface.h"
|
|
|
|
#include "wayland/pointergestures_v1_interface.h"
|
|
|
|
#include "wayland/primaryoutput_v1_interface.h"
|
|
|
|
#include "wayland/primaryselectiondevicemanager_v1_interface.h"
|
|
|
|
#include "wayland/relativepointer_v1_interface.h"
|
|
|
|
#include "wayland/seat_interface.h"
|
|
|
|
#include "wayland/server_decoration_interface.h"
|
|
|
|
#include "wayland/server_decoration_palette_interface.h"
|
|
|
|
#include "wayland/shadow_interface.h"
|
|
|
|
#include "wayland/subcompositor_interface.h"
|
|
|
|
#include "wayland/tablet_v2_interface.h"
|
|
|
|
#include "wayland/viewporter_interface.h"
|
|
|
|
#include "wayland/xdgactivation_v1_interface.h"
|
|
|
|
#include "wayland/xdgdecoration_v1_interface.h"
|
|
|
|
#include "wayland/xdgforeign_v2_interface.h"
|
|
|
|
#include "wayland/xdgoutput_v1_interface.h"
|
|
|
|
#include "wayland/xdgshell_interface.h"
|
2021-04-04 14:11:13 +00:00
|
|
|
#include "waylandoutput.h"
|
2021-07-21 10:11:21 +00:00
|
|
|
#include "waylandoutputdevicev2.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "workspace.h"
|
2022-04-22 17:54:31 +00:00
|
|
|
#include "x11window.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "xdgactivationv1.h"
|
|
|
|
#include "xdgshellintegration.h"
|
2022-04-22 18:11:29 +00:00
|
|
|
#include "xdgshellwindow.h"
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2015-05-18 09:23:45 +00:00
|
|
|
// Qt
|
Allow blacklisting some wayland interfaces
Summary:
For some interfaces, we'll look at the X-KDE-Wayland-Interfaces property in the desktop file to see which interfaces are requested.
Requires D22570.
Reviewers: #plasma, #kwin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: fvogt, zzag, broulik, graesslin, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22571
2019-07-12 15:27:32 +00:00
|
|
|
#include <QCryptographicHash>
|
2018-11-07 11:49:09 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
2015-08-17 07:42:12 +00:00
|
|
|
#include <QThread>
|
2015-05-18 09:23:45 +00:00
|
|
|
#include <QWindow>
|
|
|
|
|
2015-02-25 13:15:32 +00:00
|
|
|
// system
|
|
|
|
#include <sys/socket.h>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <sys/types.h>
|
2016-06-20 09:21:16 +00:00
|
|
|
#include <unistd.h>
|
2015-02-25 13:15:32 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// screenlocker
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2015-11-05 13:09:23 +00:00
|
|
|
#include <KScreenLocker/KsldApp>
|
2022-02-23 13:27:05 +00:00
|
|
|
#endif
|
2015-11-05 13:09:23 +00:00
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
using namespace KWaylandServer;
|
2015-02-09 12:28:37 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWIN_SINGLETON_FACTORY(WaylandServer)
|
|
|
|
|
2020-11-18 16:41:16 +00:00
|
|
|
class KWinDisplay : public KWaylandServer::FilteredDisplay
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
KWinDisplay(QObject *parent)
|
|
|
|
: KWaylandServer::FilteredDisplay(parent)
|
2022-03-23 10:13:38 +00:00
|
|
|
{
|
|
|
|
}
|
2020-11-18 16:41:16 +00:00
|
|
|
|
|
|
|
static QByteArray sha256(const QString &fileName)
|
|
|
|
{
|
|
|
|
QFile f(fileName);
|
|
|
|
if (f.open(QFile::ReadOnly)) {
|
|
|
|
QCryptographicHash hash(QCryptographicHash::Sha256);
|
|
|
|
if (hash.addData(&f)) {
|
|
|
|
return hash.result();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
bool isTrustedOrigin(KWaylandServer::ClientConnection *client) const
|
|
|
|
{
|
2020-11-18 16:41:16 +00:00
|
|
|
const auto fullPathSha = sha256(client->executablePath());
|
|
|
|
const auto localSha = sha256(QLatin1String("/proc/") + QString::number(client->processId()) + QLatin1String("/exe"));
|
|
|
|
const bool trusted = !localSha.isEmpty() && fullPathSha == localSha;
|
|
|
|
|
|
|
|
if (!trusted) {
|
|
|
|
qCWarning(KWIN_CORE) << "Could not trust" << client->executablePath() << "sha" << localSha << fullPathSha;
|
|
|
|
}
|
|
|
|
|
|
|
|
return trusted;
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
QStringList fetchRequestedInterfaces(KWaylandServer::ClientConnection *client) const
|
|
|
|
{
|
2020-11-18 16:41:16 +00:00
|
|
|
return KWin::fetchRequestedInterfaces(client->executablePath());
|
|
|
|
}
|
|
|
|
|
2021-08-22 09:49:57 +00:00
|
|
|
const QSet<QByteArray> interfacesBlackList = {
|
|
|
|
QByteArrayLiteral("org_kde_kwin_remote_access_manager"),
|
|
|
|
QByteArrayLiteral("org_kde_plasma_window_management"),
|
|
|
|
QByteArrayLiteral("org_kde_kwin_fake_input"),
|
|
|
|
QByteArrayLiteral("org_kde_kwin_keystate"),
|
|
|
|
QByteArrayLiteral("zkde_screencast_unstable_v1"),
|
|
|
|
QByteArrayLiteral("org_kde_plasma_activation_feedback"),
|
|
|
|
};
|
2020-11-18 16:41:16 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const QSet<QByteArray> inputmethodInterfaces = {"zwp_input_panel_v1", "zwp_input_method_v1"};
|
2020-11-18 16:41:16 +00:00
|
|
|
|
|
|
|
QSet<QString> m_reported;
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
bool allowInterface(KWaylandServer::ClientConnection *client, const QByteArray &interfaceName) override
|
|
|
|
{
|
2020-11-18 16:41:16 +00:00
|
|
|
if (client->processId() == getpid()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (client != waylandServer()->inputMethodConnection() && inputmethodInterfaces.contains(interfaceName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!interfacesBlackList.contains(interfaceName)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (client->executablePath().isEmpty()) {
|
2021-04-01 11:48:44 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Could not identify process with pid" << client->processId();
|
2020-11-18 16:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto requestedInterfaces = client->property("requestedInterfaces");
|
|
|
|
if (requestedInterfaces.isNull()) {
|
|
|
|
requestedInterfaces = fetchRequestedInterfaces(client);
|
|
|
|
client->setProperty("requestedInterfaces", requestedInterfaces);
|
|
|
|
}
|
|
|
|
if (!requestedInterfaces.toStringList().contains(QString::fromUtf8(interfaceName))) {
|
|
|
|
if (KWIN_CORE().isDebugEnabled()) {
|
|
|
|
const QString id = client->executablePath() + QLatin1Char('|') + QString::fromUtf8(interfaceName);
|
|
|
|
if (!m_reported.contains({id})) {
|
|
|
|
m_reported.insert(id);
|
|
|
|
qCDebug(KWIN_CORE) << "Interface" << interfaceName << "not in X-KDE-Wayland-Interfaces of" << client->executablePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto trustedOrigin = client->property("isPrivileged");
|
|
|
|
if (trustedOrigin.isNull()) {
|
|
|
|
trustedOrigin = isTrustedOrigin(client);
|
|
|
|
client->setProperty("isPrivileged", trustedOrigin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!trustedOrigin.toBool()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qCDebug(KWIN_CORE) << "authorized" << client->executablePath() << interfaceName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-09 12:28:37 +00:00
|
|
|
WaylandServer::WaylandServer(QObject *parent)
|
|
|
|
: QObject(parent)
|
2020-11-18 16:41:16 +00:00
|
|
|
, m_display(new KWinDisplay(this))
|
2015-02-09 12:28:37 +00:00
|
|
|
{
|
2020-04-29 15:18:41 +00:00
|
|
|
qRegisterMetaType<KWaylandServer::OutputInterface::DpmsMode>();
|
2015-02-09 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:38:45 +00:00
|
|
|
WaylandServer::~WaylandServer()
|
|
|
|
{
|
2021-10-07 15:26:43 +00:00
|
|
|
s_self = nullptr;
|
2015-11-10 13:38:45 +00:00
|
|
|
}
|
2015-11-10 07:52:40 +00:00
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
KWaylandServer::ClientConnection *WaylandServer::xWaylandConnection() const
|
|
|
|
{
|
|
|
|
return m_xwaylandConnection;
|
|
|
|
}
|
|
|
|
|
2021-12-13 17:29:16 +00:00
|
|
|
KWaylandServer::ClientConnection *WaylandServer::inputMethodConnection() const
|
|
|
|
{
|
|
|
|
return m_inputMethodServerConnection;
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::registerWindow(Window *window)
|
2016-04-22 12:13:37 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
if (window->readyForPainting()) {
|
|
|
|
Q_EMIT windowAdded(window);
|
2020-02-17 18:39:17 +00:00
|
|
|
} else {
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(window, &Window::windowShown, this, &WaylandServer::windowShown);
|
2020-02-17 18:39:17 +00:00
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
m_windows << window;
|
2020-02-17 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::registerXdgToplevelWindow(XdgToplevelWindow *window)
|
2020-02-17 18:39:17 +00:00
|
|
|
{
|
2020-05-07 14:29:41 +00:00
|
|
|
// TODO: Find a better way and more generic to install extensions.
|
2020-02-17 18:39:17 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
SurfaceInterface *surface = window->surface();
|
2020-07-13 11:38:12 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
registerWindow(window);
|
2020-02-17 18:39:17 +00:00
|
|
|
|
2021-05-13 06:19:44 +00:00
|
|
|
if (auto shellSurface = PlasmaShellSurfaceInterface::get(surface)) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->installPlasmaShellSurface(shellSurface);
|
2017-02-07 18:18:18 +00:00
|
|
|
}
|
2020-02-17 18:39:17 +00:00
|
|
|
if (auto decoration = ServerSideDecorationInterface::get(surface)) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->installServerDecoration(decoration);
|
2020-02-17 18:39:17 +00:00
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
if (auto decoration = XdgToplevelDecorationV1Interface::get(window->shellSurface())) {
|
|
|
|
window->installXdgDecoration(decoration);
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
2020-02-17 18:39:17 +00:00
|
|
|
if (auto menu = m_appMenuManager->appMenuForSurface(surface)) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->installAppMenu(menu);
|
2017-12-22 14:22:24 +00:00
|
|
|
}
|
2020-02-17 18:39:17 +00:00
|
|
|
if (auto palette = m_paletteManager->paletteForSurface(surface)) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->installPalette(palette);
|
2018-01-04 18:32:18 +00:00
|
|
|
}
|
2017-10-13 09:32:02 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(m_XdgForeign, &XdgForeignV2Interface::transientChanged, window, [this](SurfaceInterface *child) {
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT foreignTransientChanged(child);
|
2017-10-13 09:32:02 +00:00
|
|
|
});
|
2016-04-22 12:13:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::registerXdgGenericWindow(Window *window)
|
2020-02-17 18:39:17 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
if (auto toplevel = qobject_cast<XdgToplevelWindow *>(window)) {
|
|
|
|
registerXdgToplevelWindow(toplevel);
|
2020-02-17 18:39:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
if (auto popup = qobject_cast<XdgPopupWindow *>(window)) {
|
|
|
|
registerWindow(popup);
|
|
|
|
if (auto shellSurface = PlasmaShellSurfaceInterface::get(popup->surface())) {
|
|
|
|
popup->installPlasmaShellSurface(shellSurface);
|
2020-08-04 01:15:59 +00:00
|
|
|
}
|
2020-05-07 14:29:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Received invalid xdg shell window:" << window->surface();
|
2020-02-17 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 10:28:20 +00:00
|
|
|
void WaylandServer::initPlatform()
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
|
|
|
connect(kwinApp()->platform(), &Platform::outputAdded, this, &WaylandServer::handleOutputAdded);
|
|
|
|
connect(kwinApp()->platform(), &Platform::outputRemoved, this, &WaylandServer::handleOutputRemoved);
|
|
|
|
|
|
|
|
connect(kwinApp()->platform(), &Platform::outputEnabled, this, &WaylandServer::handleOutputEnabled);
|
|
|
|
connect(kwinApp()->platform(), &Platform::outputDisabled, this, &WaylandServer::handleOutputDisabled);
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(kwinApp()->platform(), &Platform::primaryOutputChanged, this, [this](Output *primaryOutput) {
|
2021-11-09 22:00:00 +00:00
|
|
|
m_primary->setPrimaryOutput(primaryOutput ? primaryOutput->name() : QString());
|
2021-10-25 00:05:23 +00:00
|
|
|
});
|
|
|
|
if (auto primaryOutput = kwinApp()->platform()->primaryOutput()) {
|
|
|
|
m_primary->setPrimaryOutput(primaryOutput->name());
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
const QVector<Output *> outputs = kwinApp()->platform()->outputs();
|
|
|
|
for (Output *output : outputs) {
|
2021-04-04 14:11:13 +00:00
|
|
|
handleOutputAdded(output);
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
const QVector<Output *> enabledOutputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
for (Output *output : enabledOutputs) {
|
2021-04-04 14:11:13 +00:00
|
|
|
handleOutputEnabled(output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandServer::handleOutputAdded(Output *output)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-04-14 08:32:51 +00:00
|
|
|
if (!output->isPlaceholder()) {
|
|
|
|
m_waylandOutputDevices.insert(output, new WaylandOutputDevice(output));
|
2021-07-26 23:11:50 +00:00
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandServer::handleOutputRemoved(Output *output)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-04-14 08:32:51 +00:00
|
|
|
if (!output->isPlaceholder()) {
|
|
|
|
delete m_waylandOutputDevices.take(output);
|
2021-07-26 23:11:50 +00:00
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandServer::handleOutputEnabled(Output *output)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-04-14 08:32:51 +00:00
|
|
|
if (!output->isPlaceholder()) {
|
|
|
|
m_waylandOutputs.insert(output, new WaylandOutput(output));
|
2021-07-26 23:11:50 +00:00
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandServer::handleOutputDisabled(Output *output)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-04-14 08:32:51 +00:00
|
|
|
if (!output->isPlaceholder()) {
|
|
|
|
delete m_waylandOutputs.take(output);
|
2021-07-26 23:11:50 +00:00
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
Output *WaylandServer::findOutput(KWaylandServer::OutputInterface *outputIface) const
|
2020-08-07 13:28:49 +00:00
|
|
|
{
|
2021-04-04 14:11:13 +00:00
|
|
|
for (auto it = m_waylandOutputs.constBegin(); it != m_waylandOutputs.constEnd(); ++it) {
|
|
|
|
if ((*it)->waylandOutput() == outputIface) {
|
|
|
|
return it.key();
|
2020-08-07 13:28:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
return nullptr;
|
2020-08-07 13:28:49 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 09:45:55 +00:00
|
|
|
bool WaylandServer::start()
|
|
|
|
{
|
|
|
|
return m_display->start();
|
|
|
|
}
|
|
|
|
|
2020-12-09 13:06:15 +00:00
|
|
|
bool WaylandServer::init(const QString &socketName, InitializationFlags flags)
|
2015-02-09 12:28:37 +00:00
|
|
|
{
|
2020-12-09 13:06:15 +00:00
|
|
|
if (!m_display->addSocketName(socketName)) {
|
2020-11-17 13:26:01 +00:00
|
|
|
return false;
|
2015-02-09 12:28:37 +00:00
|
|
|
}
|
2020-11-17 18:09:28 +00:00
|
|
|
return init(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WaylandServer::init(InitializationFlags flags)
|
|
|
|
{
|
|
|
|
m_initFlags = flags;
|
2020-12-09 21:24:41 +00:00
|
|
|
m_compositor = new CompositorInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_compositor, &CompositorInterface::surfaceCreated, this, [this](SurfaceInterface *surface) {
|
2022-04-22 17:39:12 +00:00
|
|
|
// check whether we have a Window with the Surface's id
|
2022-03-23 10:13:38 +00:00
|
|
|
Workspace *ws = Workspace::self();
|
|
|
|
if (!ws) {
|
|
|
|
// it's possible that a Surface gets created before Workspace is created
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (surface->client() != xWaylandConnection()) {
|
|
|
|
// setting surface is only relevant for Xwayland clients
|
|
|
|
return;
|
|
|
|
}
|
2020-11-04 13:35:37 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
X11Window *window = ws->findClient([surface](const X11Window *window) {
|
|
|
|
return window->pendingSurfaceId() == surface->id();
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2022-04-23 08:33:23 +00:00
|
|
|
if (window) {
|
|
|
|
window->setSurface(surface);
|
2022-03-23 10:13:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-04 13:35:37 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
Unmanaged *unmanaged = ws->findUnmanaged([surface](const Unmanaged *unmanaged) {
|
|
|
|
return unmanaged->pendingSurfaceId() == surface->id();
|
|
|
|
});
|
|
|
|
if (unmanaged) {
|
|
|
|
unmanaged->setSurface(surface);
|
|
|
|
return;
|
2015-02-09 15:08:53 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
|
|
|
|
// The surface will be bound later when a WL_SURFACE_ID message is received.
|
|
|
|
});
|
2018-09-14 11:04:33 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_tabletManagerV2 = new TabletManagerV2Interface(m_display, m_display);
|
|
|
|
m_keyboardShortcutsInhibitManager = new KeyboardShortcutsInhibitManagerV1Interface(m_display, m_display);
|
2020-02-17 18:39:17 +00:00
|
|
|
|
2020-09-04 07:03:04 +00:00
|
|
|
auto inputPanelV1Integration = new InputPanelV1Integration(this);
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(inputPanelV1Integration, &InputPanelV1Integration::windowCreated,
|
|
|
|
this, &WaylandServer::registerWindow);
|
2020-09-04 07:03:04 +00:00
|
|
|
|
2020-09-03 19:26:04 +00:00
|
|
|
auto xdgShellIntegration = new XdgShellIntegration(this);
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(xdgShellIntegration, &XdgShellIntegration::windowCreated,
|
|
|
|
this, &WaylandServer::registerXdgGenericWindow);
|
2020-02-17 18:39:17 +00:00
|
|
|
|
2020-08-07 19:01:42 +00:00
|
|
|
auto layerShellV1Integration = new LayerShellV1Integration(this);
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(layerShellV1Integration, &LayerShellV1Integration::windowCreated,
|
|
|
|
this, &WaylandServer::registerWindow);
|
2020-08-07 19:01:42 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_xdgDecorationManagerV1 = new XdgDecorationManagerV1Interface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_xdgDecorationManagerV1, &XdgDecorationManagerV1Interface::decorationCreated, this, [this](XdgToplevelDecorationV1Interface *decoration) {
|
2022-04-22 18:11:29 +00:00
|
|
|
if (XdgToplevelWindow *toplevel = findXdgToplevelWindow(decoration->toplevel()->surface())) {
|
2022-03-23 10:13:38 +00:00
|
|
|
toplevel->installXdgDecoration(decoration);
|
2019-01-01 17:37:18 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2019-01-01 17:37:18 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
new ViewporterInterface(m_display, m_display);
|
2015-02-09 12:28:37 +00:00
|
|
|
m_display->createShm();
|
2020-12-09 21:24:41 +00:00
|
|
|
m_seat = new SeatInterface(m_display, m_display);
|
|
|
|
new PointerGesturesV1Interface(m_display, m_display);
|
|
|
|
new PointerConstraintsV1Interface(m_display, m_display);
|
2021-10-05 18:37:58 +00:00
|
|
|
new RelativePointerManagerV1Interface(m_display, m_display);
|
2020-12-09 21:24:41 +00:00
|
|
|
m_dataDeviceManager = new DataDeviceManagerInterface(m_display, m_display);
|
|
|
|
new DataControlDeviceManagerV1Interface(m_display, m_display);
|
|
|
|
new PrimarySelectionDeviceManagerV1Interface(m_display, m_display);
|
|
|
|
m_idle = new IdleInterface(m_display, m_display);
|
2017-12-29 17:29:19 +00:00
|
|
|
auto idleInhibition = new IdleInhibition(m_idle);
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(this, &WaylandServer::windowAdded, idleInhibition, &IdleInhibition::registerClient);
|
2020-12-09 21:24:41 +00:00
|
|
|
new IdleInhibitManagerV1Interface(m_display, m_display);
|
|
|
|
m_plasmaShell = new PlasmaShellInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_plasmaShell, &PlasmaShellInterface::surfaceCreated, this, [this](PlasmaShellSurfaceInterface *surface) {
|
2022-04-23 08:33:23 +00:00
|
|
|
if (XdgSurfaceWindow *window = findXdgSurfaceWindow(surface->surface())) {
|
|
|
|
window->installPlasmaShellSurface(surface);
|
2015-06-09 17:10:56 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2020-12-09 21:24:41 +00:00
|
|
|
m_appMenuManager = new AppMenuManagerInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_appMenuManager, &AppMenuManagerInterface::appMenuCreated, this, [this](AppMenuInterface *appMenu) {
|
2022-04-23 08:33:23 +00:00
|
|
|
if (XdgToplevelWindow *window = findXdgToplevelWindow(appMenu->surface())) {
|
|
|
|
window->installAppMenu(appMenu);
|
2017-12-22 14:22:24 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2020-12-09 21:24:41 +00:00
|
|
|
m_paletteManager = new ServerSideDecorationPaletteManagerInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_paletteManager, &ServerSideDecorationPaletteManagerInterface::paletteCreated, this, [this](ServerSideDecorationPaletteInterface *palette) {
|
2022-04-23 08:33:23 +00:00
|
|
|
if (XdgToplevelWindow *window = findXdgToplevelWindow(palette->surface())) {
|
|
|
|
window->installPalette(palette);
|
2018-01-04 18:32:18 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2017-12-22 14:22:24 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_windowManagement = new PlasmaWindowManagementInterface(m_display, m_display);
|
2015-06-12 23:48:11 +00:00
|
|
|
m_windowManagement->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Disabled);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_windowManagement, &PlasmaWindowManagementInterface::requestChangeShowingDesktop, this, [](PlasmaWindowManagementInterface::ShowingDesktopState state) {
|
|
|
|
if (!workspace()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool set = false;
|
|
|
|
switch (state) {
|
|
|
|
case PlasmaWindowManagementInterface::ShowingDesktopState::Disabled:
|
|
|
|
set = false;
|
|
|
|
break;
|
|
|
|
case PlasmaWindowManagementInterface::ShowingDesktopState::Enabled:
|
|
|
|
set = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (set == workspace()->showingDesktop()) {
|
|
|
|
return;
|
2015-06-12 23:48:11 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
workspace()->setShowingDesktop(set);
|
|
|
|
});
|
[wayland] Use the new plasma virtual desktop protocol
Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)
Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)
Test Plan: used a bit a plasma session together with D12820, D13748 and D13746
Reviewers: #plasma, #kwin, graesslin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: hein, zzag, davidedmundson, kwin
Tags: #kwin
Maniphest Tasks: T4457
Differential Revision: https://phabricator.kde.org/D13887
2018-10-29 22:29:15 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_virtualDesktopManagement = new PlasmaVirtualDesktopManagementInterface(m_display, m_display);
|
[wayland] Use the new plasma virtual desktop protocol
Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)
Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)
Test Plan: used a bit a plasma session together with D12820, D13748 and D13746
Reviewers: #plasma, #kwin, graesslin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: hein, zzag, davidedmundson, kwin
Tags: #kwin
Maniphest Tasks: T4457
Differential Revision: https://phabricator.kde.org/D13887
2018-10-29 22:29:15 +00:00
|
|
|
m_windowManagement->setPlasmaVirtualDesktopManagementInterface(m_virtualDesktopManagement);
|
|
|
|
|
2021-08-22 09:49:57 +00:00
|
|
|
m_plasmaActivationFeedback = new PlasmaWindowActivationFeedbackInterface(m_display, m_display);
|
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
new ShadowManagerInterface(m_display, m_display);
|
|
|
|
new DpmsManagerInterface(m_display, m_display);
|
2015-09-01 09:30:30 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_decorationManager = new ServerSideDecorationManagerInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_decorationManager, &ServerSideDecorationManagerInterface::decorationCreated, this, [this](ServerSideDecorationInterface *decoration) {
|
2022-04-23 08:33:23 +00:00
|
|
|
if (XdgToplevelWindow *window = findXdgToplevelWindow(decoration->surface())) {
|
|
|
|
window->installServerDecoration(decoration);
|
2015-12-17 10:14:54 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2016-03-10 18:57:07 +00:00
|
|
|
|
2021-07-21 10:11:21 +00:00
|
|
|
m_outputManagement = new OutputManagementV2Interface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_outputManagement, &OutputManagementV2Interface::configurationChangeRequested, this, [](KWaylandServer::OutputConfigurationV2Interface *config) {
|
|
|
|
kwinApp()->platform()->requestOutputsChange(config);
|
2016-03-10 18:57:07 +00:00
|
|
|
});
|
2021-10-25 00:05:23 +00:00
|
|
|
m_primary = new PrimaryOutputV1Interface(m_display, m_display);
|
2016-03-21 15:44:07 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_xdgOutputManagerV1 = new XdgOutputManagerV1Interface(m_display, m_display);
|
|
|
|
new SubCompositorInterface(m_display, m_display);
|
|
|
|
m_XdgForeign = new XdgForeignV2Interface(m_display, m_display);
|
|
|
|
m_keyState = new KeyStateInterface(m_display, m_display);
|
|
|
|
m_inputMethod = new InputMethodV1Interface(m_display, m_display);
|
2020-07-11 16:40:28 +00:00
|
|
|
|
2020-11-07 02:03:57 +00:00
|
|
|
auto activation = new KWaylandServer::XdgActivationV1Interface(m_display, this);
|
|
|
|
auto init = [this, activation] {
|
|
|
|
new XdgActivationV1Integration(activation, this);
|
|
|
|
};
|
|
|
|
if (Workspace::self()) {
|
|
|
|
init();
|
|
|
|
} else {
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(static_cast<Application *>(qApp), &Application::workspaceCreated, this, init);
|
2020-11-07 02:03:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 07:09:03 +00:00
|
|
|
return true;
|
2015-06-12 23:48:11 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 19:37:03 +00:00
|
|
|
KWaylandServer::LinuxDmaBufV1ClientBufferIntegration *WaylandServer::linuxDmabuf()
|
2019-10-26 03:40:01 +00:00
|
|
|
{
|
|
|
|
if (!m_linuxDmabuf) {
|
2021-07-20 19:37:03 +00:00
|
|
|
m_linuxDmabuf = new LinuxDmaBufV1ClientBufferIntegration(m_display);
|
2019-10-26 03:40:01 +00:00
|
|
|
}
|
|
|
|
return m_linuxDmabuf;
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:32:02 +00:00
|
|
|
SurfaceInterface *WaylandServer::findForeignTransientForSurface(SurfaceInterface *surface)
|
|
|
|
{
|
|
|
|
return m_XdgForeign->transientFor(surface);
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::windowShown(Window *window)
|
2016-06-07 09:43:56 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
disconnect(window, &Window::windowShown, this, &WaylandServer::windowShown);
|
|
|
|
Q_EMIT windowAdded(window);
|
2016-06-07 09:43:56 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 23:48:11 +00:00
|
|
|
void WaylandServer::initWorkspace()
|
|
|
|
{
|
2021-10-02 08:26:51 +00:00
|
|
|
// TODO: Moe the keyboard leds somewhere else.
|
|
|
|
updateKeyState(input()->keyboard()->xkb()->leds());
|
|
|
|
connect(input()->keyboard(), &KeyboardInputRedirection::ledsChanged, this, &WaylandServer::updateKeyState);
|
|
|
|
|
[wayland] Use the new plasma virtual desktop protocol
Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)
Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)
Test Plan: used a bit a plasma session together with D12820, D13748 and D13746
Reviewers: #plasma, #kwin, graesslin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: hein, zzag, davidedmundson, kwin
Tags: #kwin
Maniphest Tasks: T4457
Differential Revision: https://phabricator.kde.org/D13887
2018-10-29 22:29:15 +00:00
|
|
|
VirtualDesktopManager::self()->setVirtualDesktopManagement(m_virtualDesktopManagement);
|
|
|
|
|
2015-06-12 23:48:11 +00:00
|
|
|
if (m_windowManagement) {
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(workspace(), &Workspace::showingDesktopChanged, this, [this](bool set) {
|
|
|
|
using namespace KWaylandServer;
|
|
|
|
m_windowManagement->setShowingDesktopState(set ? PlasmaWindowManagementInterface::ShowingDesktopState::Enabled : PlasmaWindowManagementInterface::ShowingDesktopState::Disabled);
|
|
|
|
});
|
2020-04-21 14:52:20 +00:00
|
|
|
|
|
|
|
connect(workspace(), &Workspace::workspaceInitialized, this, [this] {
|
2022-03-23 10:13:38 +00:00
|
|
|
auto f = [this]() {
|
2020-04-21 14:52:20 +00:00
|
|
|
QVector<quint32> ids;
|
2021-03-16 11:13:03 +00:00
|
|
|
QVector<QString> uuids;
|
2022-04-22 17:39:12 +00:00
|
|
|
for (Window *toplevel : workspace()->stackingOrder()) {
|
2022-04-18 08:27:27 +00:00
|
|
|
if (toplevel->windowManagementInterface()) {
|
|
|
|
ids << toplevel->windowManagementInterface()->internalId();
|
|
|
|
uuids << toplevel->windowManagementInterface()->uuid();
|
2020-04-21 14:52:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_windowManagement->setStackingOrder(ids);
|
2021-03-16 11:13:03 +00:00
|
|
|
m_windowManagement->setStackingOrderUuids(uuids);
|
2020-04-21 14:52:20 +00:00
|
|
|
};
|
|
|
|
f();
|
|
|
|
connect(workspace(), &Workspace::stackingOrderChanged, this, f);
|
|
|
|
});
|
2015-06-12 23:48:11 +00:00
|
|
|
}
|
2015-11-06 11:21:34 +00:00
|
|
|
|
2016-04-25 06:51:33 +00:00
|
|
|
if (hasScreenLockerIntegration()) {
|
2021-10-07 06:03:37 +00:00
|
|
|
initScreenLocker();
|
2017-09-30 14:33:45 +00:00
|
|
|
}
|
2021-10-10 15:22:40 +00:00
|
|
|
Q_EMIT initialized();
|
2017-09-30 14:33:45 +00:00
|
|
|
}
|
2015-11-06 14:08:13 +00:00
|
|
|
|
2017-09-30 14:33:45 +00:00
|
|
|
void WaylandServer::initScreenLocker()
|
|
|
|
{
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2020-03-15 21:40:56 +00:00
|
|
|
auto *screenLockerApp = ScreenLocker::KSldApp::self();
|
|
|
|
|
2017-09-30 14:33:45 +00:00
|
|
|
ScreenLocker::KSldApp::self()->setGreeterEnvironment(kwinApp()->processStartupEnvironment());
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::aboutToLock, this, [this, screenLockerApp]() {
|
|
|
|
if (m_screenLockerClientConnection) {
|
|
|
|
// Already sent data to KScreenLocker.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int clientFd = createScreenLockerConnection();
|
|
|
|
if (clientFd < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ScreenLocker::KSldApp::self()->setWaylandFd(clientFd);
|
2020-03-15 21:40:56 +00:00
|
|
|
|
2022-03-28 16:08:59 +00:00
|
|
|
new LockScreenPresentationWatcher(this);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const QVector<SeatInterface *> seatIfaces = m_display->seats();
|
|
|
|
for (auto *seat : seatIfaces) {
|
|
|
|
connect(seat, &KWaylandServer::SeatInterface::timestampChanged,
|
|
|
|
screenLockerApp, &ScreenLocker::KSldApp::userActivity);
|
2017-09-30 14:33:45 +00:00
|
|
|
}
|
2022-03-28 15:07:28 +00:00
|
|
|
Q_EMIT lockStateChanged();
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2020-03-15 21:40:56 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::unlocked, this, [this, screenLockerApp]() {
|
|
|
|
if (m_screenLockerClientConnection) {
|
|
|
|
m_screenLockerClientConnection->destroy();
|
|
|
|
delete m_screenLockerClientConnection;
|
|
|
|
m_screenLockerClientConnection = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<SeatInterface *> seatIfaces = m_display->seats();
|
|
|
|
for (auto *seat : seatIfaces) {
|
|
|
|
disconnect(seat, &KWaylandServer::SeatInterface::timestampChanged,
|
|
|
|
screenLockerApp, &ScreenLocker::KSldApp::userActivity);
|
2016-04-25 06:51:33 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
ScreenLocker::KSldApp::self()->setWaylandFd(-1);
|
2022-03-28 15:07:28 +00:00
|
|
|
Q_EMIT lockStateChanged();
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2017-09-30 14:33:45 +00:00
|
|
|
|
2022-02-11 16:21:42 +00:00
|
|
|
ScreenLocker::KSldApp::self()->initialize();
|
|
|
|
|
2020-03-17 05:48:05 +00:00
|
|
|
if (m_initFlags.testFlag(InitializationFlag::LockScreen)) {
|
2017-09-30 14:33:45 +00:00
|
|
|
ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate);
|
2015-11-05 13:09:23 +00:00
|
|
|
}
|
2022-02-23 13:27:05 +00:00
|
|
|
#endif
|
2015-02-20 13:54:21 +00:00
|
|
|
}
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2016-12-03 13:54:32 +00:00
|
|
|
WaylandServer::SocketPairConnection WaylandServer::createConnection()
|
2015-02-25 13:15:32 +00:00
|
|
|
{
|
2016-12-03 13:54:32 +00:00
|
|
|
SocketPairConnection ret;
|
2015-02-25 13:15:32 +00:00
|
|
|
int sx[2];
|
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) {
|
|
|
|
qCWarning(KWIN_CORE) << "Could not create socket";
|
2016-12-03 13:54:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret.connection = m_display->createClient(sx[0]);
|
|
|
|
ret.fd = sx[1];
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-03-15 21:40:56 +00:00
|
|
|
int WaylandServer::createScreenLockerConnection()
|
|
|
|
{
|
|
|
|
const auto socket = createConnection();
|
|
|
|
if (!socket.connection) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
m_screenLockerClientConnection = socket.connection;
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_screenLockerClientConnection, &KWaylandServer::ClientConnection::disconnected, this, [this]() {
|
|
|
|
m_screenLockerClientConnection = nullptr;
|
|
|
|
});
|
2020-03-15 21:40:56 +00:00
|
|
|
return socket.fd;
|
|
|
|
}
|
|
|
|
|
2016-12-03 13:54:32 +00:00
|
|
|
int WaylandServer::createXWaylandConnection()
|
|
|
|
{
|
|
|
|
const auto socket = createConnection();
|
|
|
|
if (!socket.connection) {
|
2015-02-25 13:15:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2020-07-20 08:07:08 +00:00
|
|
|
m_xwaylandConnection = socket.connection;
|
2016-12-03 13:54:32 +00:00
|
|
|
return socket.fd;
|
2015-02-25 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:21:48 +00:00
|
|
|
void WaylandServer::destroyXWaylandConnection()
|
|
|
|
{
|
2020-07-20 08:07:08 +00:00
|
|
|
if (!m_xwaylandConnection) {
|
2015-11-10 13:21:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-20 08:07:08 +00:00
|
|
|
m_xwaylandConnection->destroy();
|
|
|
|
m_xwaylandConnection = nullptr;
|
2015-11-10 13:21:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-13 02:06:12 +00:00
|
|
|
int WaylandServer::createInputMethodConnection()
|
|
|
|
{
|
2016-12-03 13:54:32 +00:00
|
|
|
const auto socket = createConnection();
|
|
|
|
if (!socket.connection) {
|
2015-06-13 02:06:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-12-03 13:54:32 +00:00
|
|
|
m_inputMethodServerConnection = socket.connection;
|
|
|
|
return socket.fd;
|
2015-06-13 02:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:38:45 +00:00
|
|
|
void WaylandServer::destroyInputMethodConnection()
|
|
|
|
{
|
|
|
|
if (!m_inputMethodServerConnection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_inputMethodServerConnection->destroy();
|
|
|
|
m_inputMethodServerConnection = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::removeWindow(Window *c)
|
2015-03-04 08:21:10 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
m_windows.removeAll(c);
|
|
|
|
Q_EMIT windowRemoved(c);
|
2015-03-04 08:21:10 +00:00
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
static Window *findWindowInList(const QList<Window *> &windows, const KWaylandServer::SurfaceInterface *surface)
|
2015-06-09 17:10:56 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
auto it = std::find_if(windows.begin(), windows.end(), [surface](Window *w) {
|
|
|
|
return w->surface() == surface;
|
|
|
|
});
|
|
|
|
if (it == windows.end()) {
|
2015-06-09 17:10:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
Window *WaylandServer::findWindow(const KWaylandServer::SurfaceInterface *surface) const
|
2015-06-09 17:10:56 +00:00
|
|
|
{
|
|
|
|
if (!surface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
if (Window *c = findWindowInList(m_windows, surface)) {
|
2015-06-09 17:10:56 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-22 18:11:29 +00:00
|
|
|
XdgToplevelWindow *WaylandServer::findXdgToplevelWindow(SurfaceInterface *surface) const
|
2016-08-22 14:55:48 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
return qobject_cast<XdgToplevelWindow *>(findWindow(surface));
|
2016-08-22 14:55:48 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 18:11:29 +00:00
|
|
|
XdgSurfaceWindow *WaylandServer::findXdgSurfaceWindow(SurfaceInterface *surface) const
|
2020-08-04 01:15:59 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
return qobject_cast<XdgSurfaceWindow *>(findWindow(surface));
|
2020-08-04 01:15:59 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 10:19:38 +00:00
|
|
|
bool WaylandServer::isScreenLocked() const
|
|
|
|
{
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2016-04-25 06:51:33 +00:00
|
|
|
if (!hasScreenLockerIntegration()) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
return ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::Locked || ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::AcquiringLock;
|
2022-02-23 13:27:05 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2015-11-16 10:19:38 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 06:51:33 +00:00
|
|
|
bool WaylandServer::hasScreenLockerIntegration() const
|
|
|
|
{
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2020-03-17 05:48:05 +00:00
|
|
|
return !m_initFlags.testFlag(InitializationFlag::NoLockScreenIntegration);
|
2022-02-23 13:27:05 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2016-04-25 06:51:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 12:09:37 +00:00
|
|
|
bool WaylandServer::hasGlobalShortcutSupport() const
|
|
|
|
{
|
2020-03-17 05:48:05 +00:00
|
|
|
return !m_initFlags.testFlag(InitializationFlag::NoGlobalShortcuts);
|
2018-12-02 12:09:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-29 17:29:19 +00:00
|
|
|
void WaylandServer::simulateUserActivity()
|
|
|
|
{
|
|
|
|
if (m_idle) {
|
|
|
|
m_idle->simulateUserActivity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 16:36:32 +00:00
|
|
|
void WaylandServer::updateKeyState(KWin::LEDs leds)
|
2019-06-21 14:02:50 +00:00
|
|
|
{
|
2022-03-25 12:20:32 +00:00
|
|
|
if (!m_keyState) {
|
2019-06-21 14:02:50 +00:00
|
|
|
return;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2019-06-21 14:02:50 +00:00
|
|
|
|
2021-10-04 16:36:32 +00:00
|
|
|
m_keyState->setState(KeyStateInterface::Key::CapsLock, leds & KWin::LED::CapsLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked);
|
|
|
|
m_keyState->setState(KeyStateInterface::Key::NumLock, leds & KWin::LED::NumLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked);
|
|
|
|
m_keyState->setState(KeyStateInterface::Key::ScrollLock, leds & KWin::LED::ScrollLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked);
|
2019-06-21 14:02:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 08:45:02 +00:00
|
|
|
bool WaylandServer::isKeyboardShortcutsInhibited() const
|
|
|
|
{
|
|
|
|
auto surface = seat()->focusedKeyboardSurface();
|
|
|
|
if (surface) {
|
|
|
|
auto inhibitor = keyboardShortcutsInhibitManager()->findInhibitor(surface, seat());
|
|
|
|
return inhibitor && inhibitor->isActive();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-17 13:26:01 +00:00
|
|
|
QString WaylandServer::socketName() const
|
|
|
|
{
|
|
|
|
const QStringList socketNames = display()->socketNames();
|
|
|
|
if (!socketNames.isEmpty()) {
|
|
|
|
return socketNames.first();
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2022-03-28 16:08:59 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
|
|
|
WaylandServer::LockScreenPresentationWatcher::LockScreenPresentationWatcher(WaylandServer *server)
|
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(server, &WaylandServer::windowAdded, this, [this](Window *window) {
|
|
|
|
if (window->isLockScreen()) {
|
|
|
|
connect(window->output()->renderLoop(), &RenderLoop::framePresented, this, [this, window]() {
|
2022-03-28 16:08:59 +00:00
|
|
|
// only signal lockScreenShown once all outputs have been presented at least once
|
2022-04-23 08:33:23 +00:00
|
|
|
m_signaledOutputs << window->output();
|
2022-03-28 16:08:59 +00:00
|
|
|
if (m_signaledOutputs.size() == kwinApp()->platform()->enabledOutputs().size()) {
|
|
|
|
ScreenLocker::KSldApp::self()->lockScreenShown();
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
QTimer::singleShot(1000, this, [this]() {
|
|
|
|
ScreenLocker::KSldApp::self()->lockScreenShown();
|
|
|
|
delete this;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
#endif
|
2015-02-09 12:28:37 +00:00
|
|
|
}
|